JavaScript has 7 primitive types, and everything else (arrays, functions, objects) is an object.
The primitives: string, number, boolean, , , , .
JavaScript has 7 primitive types, and everything else (arrays, functions, objects) is an object.
The primitives: string, number, boolean, , , , .
nullundefinedbigintsymboltypeof "hi"; // "string"
typeof 42; // "number" (both ints and floats)
typeof true; // "boolean"
typeof undefined; // "undefined"
typeof 10n; // "bigint"
typeof Symbol(); // "symbol"
typeof null; // "object" ← famous historical bug!
typeof {}; // "object"
typeof []; // "object" (arrays are objects)
typeof function(){};// "function"
1. Primitives are immutable and copied by value; objects are copied by reference.
let a = 5; let b = a; b++; // a is still 5 (independent copies)
let x = {n:1}; let y = x; y.n = 2; // x.n is now 2 (same object!)
2. typeof null === "object" is a long-standing language bug you must remember — to check for null, compare directly (x === null).
Understanding value-vs-reference explains why mutating a shared object affects "both" variables, why {} === {} is false, and why you copy objects (spread) before changing them in state-driven UIs like React.