In JavaScript, you can assign different types of values (data) to a variable e.g. string, number, boolean, etc.
Example:
A variable with different data types
let myvariable=1;//numeric value
myvariable='one';//string value
myvariable=true;//boolean value
In the above example, different types of values are assigned to the same variable to demonstrate the loosely typed characteristics of JavaScript. Here, 1 is the number type, 'one' is the string type, and true is the boolean type.
JavaScript includes primitive and non-primitive data types as per the latest ECMAScript 5.1 specification.
The primitive data types are the lowest level of the data value in JavaScript. The followings are primitive data types in JavaScript:
Data type | Description |
---|---|
String | String is a textual content wrapped inside ' ' or " " or ` ` (tick sign). |
Number | Number is a numeric value. |
BigInt | BigInt is a numeric value in the arbitrary precision format. |
Boolean | Boolean is a logical data type that has only two values, true or false. |
Null | A null value denotes an absense of value. |
Undefined | undefined is the default value of a variable that has not been assigned any value. |
The structural data types contain some kind of structure with primitive data.
Data type | Description |
---|---|
Object | An object holds multiple values in terms of properties and methods. |
Date | The Date object represents date & time including days, months, years, hours, minutes, seconds, and milliseconds. |
Array | An array stores multiple values using special syntax. |