Chapter VII · Objects
Object References
Objects are reference types, meaning variables store memory addresses rather than the actual data value.
01 How It Works
Think of two people holding keys pointing to the exact same physical storage locker.
Assigning or passing an object copies its reference link, not a clone of its internal properties.
example.js
const obj1 = { value: 10 };
const obj2 = obj1;
obj2.value = 20;
console.log(obj1.value); // 20 (Shared reference)
1. Create an object assigned to a variable reference.
2. Assign that variable to a second variable.
3. Modify properties through either variable to see shared effects.
02 Practical Example
Here is how you might see this concept applied in real-world code:
practical.js
const original = { x: 1 };
const copyRef = original;
console.log(original === copyRef); // true
Key Takeaway
Be mindful of shared mutations when copying object references.