- Primitive data type
- Non-primitive (reference) data type
- String- represents a sequence of characters e.g. "hello"
- Number- represents numeric values e.g. 100
- Boolean- represents boolean value either false or true
- Undefined- represents an undefined value
- Null- represents null i.e. no value at all
- The non-primitive data types are:
- Object- represents instance through which we can access members
- Array- represents a group of similar values
- RegExp- represents regular expression
Primitive data types:
A string (or a text string) is a series of characters. Strings are written with quotes. They can be represented by using either of single or double quotes.
var carName = "Volvo"; // Using double quotes
var carName = 'Volvo'; // Using single quotes
var x1 = 34.00; // Written with decimals
var x2 = 34; // Written without decimals
Note: Extra large or extra small numbers can be written with scientific (exponential) notation.
Booleans can only have two values: true or false.
var x = true;
var y = false;
Booleans are often used in conditional testing.
Non-primitive data types:
Object properties are written in key:value pairs, which are separated by commas.
The object (person) in the example above has 4 properties: firstName, lastName, age, and eyeColor.