JavaScript Data Types

In JavaScript, you can assign different types of values (data) to a variable e.g. string, number, boolean, etc.

Example: A Variable with Different Types of Data
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.

Primitive Data Types

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).

Example: 'Hello World!', "This is a string", etc.
Number Number is a numeric value.

Example: 100, 4521983, etc.
BigInt BigInt is a numeric value in the arbitrary precision format.

Example: 453889879865131n, 200n, etc.
Boolean Boolean is a logical data type that has only two values, true or false.
Null A null value denotes an absense of value.

Example: let str = null;
Undefined undefined is the default value of a variable that has not been assigned any value.

Example: In the variable declaration, var str;, there is no value assigned to str. So, the type of str can be check using typeof(str) which will return undefined.

Structural Data Types

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.

Example:
let person = { 
                firstName: "James", 
                lastName: "Bond", 
                age: 15
            }; 
Date The Date object represents date & time including days, months, years, hours, minutes, seconds, and milliseconds.

Example: let today = new Date("25 July 2021");
Array An array stores multiple values using special syntax.

Example: let nums = [1, 2, 3, 4];

Learn about each data type in detail in the next section.

Want to check how much you know JavaScript?