Glossary / Object identity
Object identity
Object identity is the sameness of a particular object reference in memory. Two variables with the same reference observe the same mutable object; two separately created objects are distinct even if all their properties match. Identity affects equality, aliasing, Map/Set keys, memoization, UI updates, and garbage-collection reachability.
Identity is not a domain ID
const first = { id: "u-1" };
const second = { id: "u-1" };
first === second; // false
first.id === second.id; // true
The first comparison asks whether both values point to one object; the second compares an explicit field. Object identity is process-local and does not survive JSON serialization, persistence, or crossing a worker/service boundary. Parsing the same JSON twice creates distinct objects. Use stable identifiers for entities that must be recognized across requests or reloads.
Aliasing means mutation through one reference is visible through others. Identity-based caches can become stale when an object is mutated in place. WeakMap and WeakSet use identity while allowing keys/values to become collectible. When identity is important, document ownership and whether mutation is allowed.
Interview questions
- Are two objects with identical fields identical? No, unless they are the same reference.
- Does object identity survive JSON serialization? No.
- How recognize the same user across requests? Compare a stable domain identifier, not object references.
- How can aliasing cause bugs? One consumer mutates shared state unexpectedly visible to another.