Course contentsShow
← JavaScript
Lesson 700 of 2,72317. Prototypes and InheritanceFree lesson

The __proto__ Accessor

Understanding __proto__ as a legacy way to access the prototype chain.

The proto Accessor

What You'll Learn: You'll discover __proto__ as an older way to directly access an object's prototype, and why modern code prefers alternatives.

What is proto?

__proto__ is a special property that provides direct read/write access to an object's internal prototype link. It's essentially a legacy shortcut that does the same job as Object.getPrototypeOf(), but with a simpler syntax.

Think of __proto__ like an old map that still shows the roads, but newer maps are clearer and more reliable.

How It Works

When you access obj.__proto__, you're seeing the prototype object that obj inherits from:

const parent = { greet: "Hello" };
const child = Object.create(parent);

console.log(child.__proto__ === parent); // true
console.log(child.__proto__.greet);      // "Hello"

You can even change the prototype by assigning to __proto__:

const newParent = { farewell: "Goodbye" };
child.__proto__ = newParent;

console.log(child.farewell); // "Goodbye"
console.log(child.greet);    // undefined (old prototype replaced)

Why You've Already Learned a Better Way

You already know Object.getPrototypeOf(), which does the reading part more reliably. __proto__ was never part of the official JavaScript specification initially—it was added later for compatibility with old browsers. Modern code should avoid it because:

  • It's slower than Object.getPrototypeOf()
  • It can cause confusion
  • Not all objects have __proto__ available

Key Takeaway: __proto__ is a legacy accessor for the prototype chain—use Object.getPrototypeOf() for reading prototypes in modern code, and avoid modifying prototypes after object creation.