Data Types

Data types are used to classify eight fundamental values used for programming in JavaScript, including primitive and object types.

Primitive Data Types

JavaScript uses seven primitive data types that are listed in the table below:

Data Type Wrapper Object Description
number Number Any number, including numbers with decimals: 1, -2, 99, 3.14.
bigint BigInt Any number, greater than 253-1 or less than -(253-1) with n appended to the number: 1234567890123456n.
string String Any grouping of characters on your keyboard (letters, numbers, spaces, symbols, etc.) surrounded by single '' or double "".
boolean Boolean This data type only has two possible values — either true or false.
null None This data type represents the intentional absence of a value, and is represented by the keyword null.
undefined None This data type is denoted by the keyword undefined. It also represents the absence of a value though it has a different use than null.
symbol Symbol A newer feature to the language, symbols are unique identifiers, useful in more complex coding. No need to worry about these for now.

Objects

Objects are a little more complex since they are collections of related data.

Note: The null type cannot be tested with typeof like all the other primitive types because it will return "object". This must be tested with the type equality operator (i.e., === null).

Number and BigInt

let num = 7;
let bigNum = 9999999999999999n;

BigInt is necessary for large whole numbers because they are unreliable with the Number type:

console.log(9999999999999999);
console.log(9999999999999999n);

This will output the following:

10000000000000000
9999999999999999n

String

Strings in JavaScript can be defined with either ' ' or " ".

let greeting = 'Hi buddy';
let message = 'You are doing great! Keep studying!';

Boolean

Boolean is for truthy or falsy values:

let lateToWork = true;
let isTheEarthFlat = false;

Null and Undefined

Null and Undefined are both for the absence of a value, but they have different meanings.

// Undefined means there should be some values, but it is undefined now
let finishCourseTime = undefined;
// Null means there is no value here
let finishStudyingDate = null;

Object

Objects can have fields with different values and types inside:

const user = {
name: 'Jane',
age: 20,
isActive: true,
};

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn JavaScript on Codecademy