JavaScript has seven primitive data types: string, number, bigint, boolean, undefined, null and symbol. Older tutorials list six because bigint was added in ES2020. Primitives are immutable values that are compared by value, and everything else in JavaScript is an object.
Knowing the primitives helps you predict how assignment, comparison and typeof behave, and it explains many common bugs.
| Type | Example | typeof result |
|---|---|---|
string | 'hello' | "string" |
number | 42, 3.14, NaN, Infinity | "number" |
bigint | 9007199254740993n | "bigint" |
boolean | true, false | "boolean" |
undefined | undefined | "undefined" |
null | null | "object" (historical bug) |
symbol | Symbol('id') | "symbol" |
typeof null returning "object" is a long-standing quirk that cannot be fixed without breaking existing code. Test for null with value === null.
A number is a 64-bit IEEE 754 double. There is no separate integer type, so 1 and 1.0 are the same value. Floating-point rounding applies, and the safe integer range ends at Number.MAX_SAFE_INTEGER (2^53 - 1).
Use bigint when you need exact integers beyond the safe range, such as database IDs or cryptographic values. Add an n suffix or call BigInt(). You cannot mix bigint and number in arithmetic.
A boolean is true or false. Any value can be converted with Boolean(value). The falsy values are false, 0, -0, 0n, '', null, undefined and NaN. Everything else is truthy.
A string is an immutable sequence of UTF-16 code units. Use single quotes, double quotes or backticks. Template literals allow interpolation and multi-line text.
Because strings are immutable, methods such as toUpperCase() and replace() return a new string and never change the original. Strings are primitives, yet you can call methods on them because JavaScript wraps them in a temporary String object for the call.
undefined means a value was never assigned. It is the default for declared variables, missing function arguments, missing object properties and functions with no return. null means an intentional empty value that you set yourself.
The nullish coalescing operator ?? and optional chaining ?. handle both values neatly:
A symbol is a unique, immutable value, mainly used as an object key that cannot collide with other keys. Two symbols created with the same description are still different.
Well-known symbols such as Symbol.iterator let your objects take part in language features like for...of.
Primitives are copied by value. Objects, arrays and functions are copied by reference.
Primitives have no properties of their own, and you cannot add any: 'abc'.extra = 1 does nothing in sloppy mode and throws a TypeError in strict mode.
null a primitive or an object?It is a primitive. typeof null returns "object" because of an early implementation mistake that was kept for compatibility.
No. Arrays, functions, dates and plain objects are all objects. typeof [] returns "object", so use Array.isArray.
bigint was added in ES2020, and symbol in ES2015. Older articles that list six predate bigint.
No. Operations on a primitive produce a new value. A variable declared with let can be reassigned, but the value itself never changes.
JavaScript has seven primitives: string, number, bigint, boolean, undefined, null and symbol. They are immutable and compared by value, unlike objects, which are compared by reference. Remember the typeof null quirk, use bigint for large integers, and rely on ?? and ?. to handle null and undefined.