Course contentsShow
← JavaScript
Lesson 597 of 2,72315. ObjectsFree lesson

Objects Are Reference Types

Understand that object variables hold references, not copies of the object.

Objects Are Reference Types

What You'll Learn

You'll discover that when you assign an object to a variable, you're storing a reference to that object, not a separate copy of it.

The Core Idea

When you work with primitive values like numbers or strings, each variable holds its own independent copy of the value. But objects work differently—variables hold a reference (think: a pointer or address) to the object in memory, not the object itself.

This means multiple variables can reference the same object. Changes made through one variable affect what you see through all other variables pointing to that same object.

Think of It Like an Address

Imagine an object is a house. A primitive value is like writing down the entire blueprint of the house on paper—every copy is independent. But an object variable is like writing down the address of the house. Multiple people can have the same address written on different pieces of paper, but they're all pointing to the same physical house. If someone repaints the house, everyone who visits that address sees the new color.

How This Works in Practice

let person1 = { name: "Alice", age: 30 };
let person2 = person1;  // person2 now references the SAME object

person2.age = 31;

console.log(person1.age);  // 31 (not 30!)
console.log(person2.age);  // 31

Both person1 and person2 reference the same object in memory. Changing a property through person2 affects what person1 sees because there's only one actual object.

Key Takeaway: Object variables store references to objects, not copies. Multiple variables can point to the same object, so changes through one variable affect all references to that object.