JavaScript has eight data types: seven primitive types (string, number, bigint, boolean, undefined, null, and symbol) and one non-primitive type, object. Primitive values are immutable and compared by value, while objects, including arrays, functions, dates, maps, and sets, are compared by reference.
You can inspect the type of a value at runtime with the typeof operator, though it has a few quirks covered below.
| Type | Category | Example | typeof result |
|---|---|---|---|
| String | Primitive | "hello" | "string" |
| Number | Primitive | 42, 3.14, NaN | "number" |
| BigInt | Primitive | 9007199254740993n | "bigint" |
| Boolean | Primitive | true | "boolean" |
| Undefined | Primitive | undefined | "undefined" |
| Null | Primitive | null | "object" (historical bug) |
| Symbol | Primitive | Symbol("id") | "symbol" |
| Object | Non-primitive | {}, [], new Date() | "object" or "function" |
JavaScript is dynamically typed. A variable has no fixed type; the value it currently holds does.
Text enclosed in single quotes, double quotes, or backticks. Template literals support interpolation and multi-line text.
A single type covers integers and floating-point values, stored as 64-bit IEEE 754 doubles. Integers are exact only up to Number.MAX_SAFE_INTEGER (2^53 - 1). Special values include NaN, Infinity, and -Infinity.
Arbitrary-precision integers, added in ES2020. Write them with an n suffix. You cannot mix bigint and number in arithmetic without converting explicitly.
Either 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.
undefined means a value has not been assigned. null is an intentional "no value" that you assign yourself.
A unique, immutable value, often used as a property key that cannot collide with other keys.
Everything that is not a primitive is an object: plain objects, arrays, functions, Date, Map, Set, RegExp, and class instances. Objects hold collections of properties and are copied by reference.
Functions are objects that can be called, so typeof reports them as "function".
Use these checks when typeof is not precise enough:
Primitives are copied by value and cannot be mutated. Strings, for example, never change in place; methods return a new string.
When you call a method on a primitive, JavaScript temporarily wraps it in an object. You should not create these wrappers yourself with new String() or new Number(), because typeof new Number(1) is "object" and comparisons behave unexpectedly.
Use Object.freeze() to make an object shallowly immutable, and structuredClone() to make a deep copy of plain data.
Eight: string, number, bigint, boolean, undefined, null, symbol, and object. Older tutorials list six or seven because bigint and symbol were added in ES2020 and ES2015.
No. Arrays are objects, and typeof [] returns "object". Use Array.isArray() to detect them.
undefined is the default for something that has no value yet, while null is a value you set to mean "intentionally empty". They are loosely equal with == but not strictly equal with ===.
Dynamically typed: types belong to values, not variables. TypeScript adds optional static types that are checked at compile time and erased at runtime.
JavaScript has seven primitives and one non-primitive type, object. Primitives are immutable and compared by value; objects are compared by reference. Use typeof for primitives, and === null, Array.isArray(), or instanceof for the cases where typeof returns "object".