Skip to main content

Data types in JS

JavaScript has 8 basic data types. They are split into primitive and reference (object) types.


1. Primitive types (7 total)

A primitive is a value that is not an object and has no methods. They are stored by value, not by reference.


Number

Numbers - both integers and floating-point.

javascript
let a = 42; let b = 3.14;

Notes:

  • Special values exist: Infinity, -Infinity, NaN (Not-a-Number).
  • All numbers in JS are 64-bit floating-point numbers (IEEE 754).

BigInt

Used for very large integers that exceed the limits of Number.

javascript
let big = 123456789012345678901234567890n;

Adds the n suffix. Lets you work precisely with integers of any length.


String

Text strings in quotes: 'single', "double", or template quotes.

javascript
let name = "Tim"; let message = `Hello, ${name}!`;

Strings are immutable - a new string is created on any change.


Boolean

Logical values - true or false.

javascript
let isAdmin = true; let isLoggedIn = false;

Used in conditions, checks, and logical expressions.


Null

A special value denoting "nothing" or "empty".

javascript
let user = null;

Its type is object (a historical mistake in JavaScript that stuck).


Undefined

A variable declared but with no assigned value.

javascript
let x; console.log(x); // undefined

Assigned automatically when no value is set.


Symbol

A unique, immutable value often used as an object key.

javascript
let id = Symbol('id'); let obj = { [id]: 123 };

Every Symbol is unique, even with the same description.


2. Reference type

Object

Stores collections of data and functions. Passed by reference, not by value.

javascript
let user = { name: "Tim", age: 25 }; let arr = [1, 2, 3]; let func = function() {};

Object subtypes:

  • Object - the base type.
  • Array - an array.
  • Function - a function.
  • Date, RegExp, Map, Set, and so on.
Data typeExampleDescription
Number42, 3.14, NaNNumbers
BigInt123nLarge integers
String'Hello', Hi ${name}Strings
Booleantrue, falseLogical type
NullnullAbsence of value
UndefinedundefinedNot defined
SymbolSymbol('id')Unique identifier
Object{}, [], function(){}Collections and structures

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.