String, Number, Boolean, Array, Object, Null, Undefined.
JavaScript has dynamic types. This means that the same variable can be used as different types:
A string is a variable which stores a series of characters like "John Doe".
A string can be any text inside quotes. You can use single or double quotes:
You can use quotes inside a string, as long as they don't match the quotes surrounding the string:
You will learn a lot more about strings in the advanced section of this tutorial.
JavaScript has only one type of numbers. Numbers can be written with, or without decimals:
Extra large or extra small numbers can be written with scientific (exponential) notation:
You will learn a lot more about numbers in the advanced section of this tutorial.
Booleans can only have two values: true or false.
Booleans are often used in conditional testing. You will learn more about conditional testing in a later chapter of this tutorial.
The following code creates an Array called cars:
or (condensed array):
or (literal array):
Array indexes are zero-based, which means the first item is [0], second is [1], and so on.
You will learn a lot more about arrays in later chapters of this tutorial.
An object is delimited by curly braces. Inside the braces the object's properties are defined as name and value pairs (name : value). The properties are separated by commas:
The object (person) in the example above has 3 properties: firstname, lastname, and id.
Spaces and line breaks are not important. Your declaration can span multiple lines:
You can address the object properties in two ways:
You will learn a lot more about objects in later chapters of this tutorial.
Undefined is the value of a variable with no value.
Variables can be emptied by setting the value to null;
When you declare a new variable, you can declare its type using the "new" keyword:
| JavaScript variables are all objects. When you declare a variable you create a new object. |
The perfect solution for professionals who need to balance work, family, and career building.
More than 10 000 certificates already issued!
The HTML Certificate documents your knowledge of HTML.
The HTML5 Certificate documents your knowledge of advanced HTML5.
The CSS Certificate documents your knowledge of advanced CSS.
The JavaScript Certificate documents your knowledge of JavaScript and HTML DOM.
The jQuery Certificate documents your knowledge of jQuery.
The XML Certificate documents your knowledge of XML, XML DOM and XSLT.
The ASP Certificate documents your knowledge of ASP, SQL, and ADO.
The PHP Certificate documents your knowledge of PHP and SQL (MySQL).
Your message has been sent to W3Schools.