foundation
Object values
Reference identity, property bags, arrays, functions as objects, and wrapper object caveats.
Objects (including arrays and functions) are reference values. Assignment copies the reference, so two variables can point at the same mutable structure. `{}` === `{}` is false because identity differs even when shape matches.
Property keys are strings or symbols (Map allows any key type). `Object.is(a, a)` checks reference identity. Spread and `Object.assign` make shallow copies — nested objects remain shared.
const a = { nested: { count: 1 } };
const b = { ...a };
b.nested.count = 2;
console.log(a.nested.count); // 2
Prefer Map when keys are not strings/symbols or when you need reliable size and iteration order without prototype pollution.
On interviews, explain the concept with a concrete example and name the runtime behavior interviewers probe.
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:
- Explain reference assignment.
- Compare object identity with shape equality.
- Call out shallow copy limits.