Mutating Objects Through Multiple References
You'll learn: How changing an object through one variable affects all other variables pointing to that same object.
The Core Idea
When you have multiple variables referencing the same object, mutating (changing) the object through any of those references affects what you see through all of them. This happens because all the variables point to the same location in memory—they're different names for the same thing.
Think of it like a house with multiple doors. Whether you enter through the front door or back door, any changes you make inside affect what everyone sees, no matter which door they use.
How It Works
When you assign an object to a new variable, you're copying the reference (the address), not the object itself. So both variables point to the exact same object:
let person1 = { name: "Alice" };
let person2 = person1; // person2 now references the SAME object
person2.name = "Bob"; // Mutate through person2
console.log(person1.name); // "Bob" - person1 sees the change!
console.log(person2.name); // "Bob"
Both person1 and person2 reference the identical object. Changing name through person2 mutates that shared object, so person1 reflects the change immediately.
Why This Matters
This behavior can surprise beginners. You might think each variable has its own copy, but they don't—they share one object. Understanding this prevents bugs where you accidentally modify data you thought was independent.
Key Takeaway: When multiple variables reference the same object, mutating the object through one reference changes what all references see, because they all point to the same object in memory.