Dmytro Morar
JavaScript

Data Types

In JavaScript, there are two main data types: primitive and reference. Primitives store the value itself, while reference types store a reference to the memory area where the value is located.

Primitive Types

Store the actual value, not a reference. Passed by value.

TypeDescription
NumberNumeric values: 10, 3.14, -5
StringText strings: "Hello", 'JS'
BooleanLogical values: true, false
NullIntentional absence of a value
UndefinedVariable declared but without a value
SymbolUnique and immutable identifier
BigIntVery large integers, larger than Number.MAX_SAFE_INTEGER
typeof 42; // 'number'
typeof "Hello"; // 'string'
typeof null; // 'object' (historical bug)
typeof Symbol(); // 'symbol'

Primitives are immutable — their values cannot be changed without creating a new one.

Reference Types

Store a reference (address) to an object in memory. Passed by reference.

TypeDescription
ObjectCollection of key–value pairs
ArrayOrdered list of values (a special type of object)
FunctionObject that can be called (has an internal [[Call]] method)
typeof {}; // 'object'
typeof []; // 'object'
typeof function () {}; // 'function'

Arrays and functions are subtypes of objects, so typeof [] returns 'object'.

Key Ideas

  • Primitives store values directly → immutable, compared by value.
  • Reference types store references → mutable, compared by memory address.
  • typeof null === 'object' — a historical bug in the language.
  • Functions have their own function type, although they are a subtype of object.
  • For accurate type determination of complex structures, use:
Array.isArray([]); // true
obj.constructor === Object; // true

On this page