JavaScript Object Identity and Shared References
Quick answer
Objects have identity and can contain properties. Two objects with matching property values can still be distinct. When a variable receives an object value already held by another binding, both bindings can refer to the same object.
How it works
An object literal such as { points: 1 } creates a new object each time it is evaluated. Dot notation reads a named property. Strict equality between objects tests identity, not their structure. Assignment copies the value (an object reference-like value for objects), not the entire object. Function arguments also pass values, not aliases to the caller’s variable binding.
const first = { points: 1 };const second = { points: 1 };console.log(first === second);Expected output in Node.js:
falseEach literal creates a distinct object.
const first = { points: 1 };const alias = first;alias.points = 6;console.log(first.points);console.log(alias === first);Expected output in Node.js:
6trueBoth names identify the same object.
Common mistakes
Do not assume const alias = first clones an object. Changing a property is different from reassigning a binding. A full object chapter will cover copying and property semantics.
Practice
Create a local object using a supplied numeric value, alias it, update the shared property and return the observed value through the original binding.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
JavaScript Object Identity and Shared References — Knowledge Check
Apply the taught concept and reason about the result.
What is { a: 1 } === { a: 1 } when each is evaluated as an object expression?
What does const a = { n: 2 }; const b = a; b.n = 7; console.log(a.n); print?
What does assigning an existing object to another variable do?
What does strict equality compare for ordinary objects?
Which statement about function arguments is accurate?