Primitives vs Objects in JavaScript
JavaScript has seven primitives — string, number, bigint, boolean, undefined, symbol, null — copied by value and compared by value, plus objects (including arrays and functions) copied and compared by reference. This single divide explains 2 + 2 equaling 4 while [2] + [2] gives the string "22", and why const arr = [] still allows arr.push().
Primitives are immutable (methods return new values; the original never changes), while objects mutate through any live reference. Primitives also auto-box temporarily when you call methods on them ("hi".length works because a wrapper object briefly exists), then discard the wrapper.
Seven primitives
string, number, bigint, boolean, undefined, symbol, null — everything else (arrays, functions, dates) is an object.
Value vs reference
Primitives copy the value (a = b snapshots); objects copy the address (two names, one shared object).
Primitives never mutate
s.toUpperCase() returns a new string — the original is untouched, always, by design.
Auto-boxing on access
"hi".length briefly wraps the primitive to read a property, then discards the wrapper — convenient, invisible, occasionally surprising.
let a = 5;let b = a;b = 6;let arr1 = [1];let arr2 = arr1;arr2.push(2);console.log(a, b, arr1.length);Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in JavaScript yourself — building beats watching.