JavaScript Data Types
JavaScript has primitive types — `string`, `number`, `boolean`, `undefined`, `null`, `symbol`, `bigint` — and one composite type, `object` (which includes arrays and functions).
JavaScript is dynamically typed: a variable's type is determined at runtime and can change if reassigned to a different kind of value.
Primitives
Primitives are immutable and compared by value. `typeof` reveals a value's type, though `typeof null` famously returns 'object' due to a historical bug.
Objects
Objects, arrays, and functions are all technically objects in JS. They are compared by reference, not by value.
console.log(typeof "hi");
console.log(typeof 42);
console.log(typeof true);
console.log(typeof undefined);string
number
boolean
undefinedtypeof reports the primitive type of a value.
let arr = [1,2,3];
console.log(typeof arr, Array.isArray(arr));object trueArrays report as 'object' via typeof, so use Array.isArray to check specifically.
Key points
- Primitives: string, number, boolean, undefined, null, symbol, bigint.
- Objects (including arrays, functions) are the only composite type.
- `typeof null` returns 'object' — a known quirk.
- JavaScript is dynamically typed.
