foundation

Primitive values

String, number, bigint, boolean, symbol, undefined, null, and immutable primitive behavior.

JavaScript has seven primitive types: string, number, bigint, boolean, symbol, undefined, and null. Primitives are copied by value — assignment copies the value, not a shared reference. You cannot mutate a primitive; methods like `"abc".toUpperCase()` return new values.

`typeof null === "object"` is a legacy bug. `typeof` arrays return `"object"`. `Object.is(NaN, NaN)` is true while `NaN === NaN` is false. `Object.is(-0, +0)` is false while `===` treats them as equal.

Boxing wraps primitives in temporary objects so methods work: `(42).toFixed(2)` boxes the number briefly.

On interviews: separate primitive equality from object identity, explain boxing, and mention NaN and signed-zero edge cases.

Common pitfalls include mixing similar APIs and forgetting edge cases during live coding.

The trade-off is often clarity versus performance or safety versus convenience.

Checklist:

  • List all seven primitive types.
  • Explain value copy versus reference identity.
  • Mention NaN, -0, and typeof null.