Accessing [[Prototype]] with proto
You'll learn how to read and write an object's internal prototype link using the __proto__ accessor property.
Every JavaScript object has a hidden internal slot called [[Prototype]] that links it to another object (or null). While [[Prototype]] is internal and not directly accessible, JavaScript provides __proto__ as a convenient way to get or set this link.
What is __proto__?
__proto__ is an accessor property (a getter/setter pair) that exists on Object.prototype. When you read obj.__proto__, it returns the object's internal [[Prototype]]. When you write to it, you change that link.
const parent = { name: "parent" };
const child = { age: 5 };
// Read the prototype
console.log(child.__proto__); // Object.prototype (the default)
// Set the prototype
child.__proto__ = parent;
// Now child inherits from parent
console.log(child.name); // "parent"
console.log(child.__proto__ === parent); // true
__proto__ vs Object.getPrototypeOf()
While __proto__ works, Object.getPrototypeOf() is the preferred modern way to read a prototype. Both do the same thing:
const obj = {};
console.log(obj.__proto__ === Object.getPrototypeOf(obj)); // true
Why the Double Underscore?
The __ prefix signals that __proto__ was originally a non-standard feature (browsers added it before it was officially part of JavaScript). It's now standardized but considered legacy.
Key Takeaway: __proto__ is an accessor property that exposes an object's [[Prototype]] link for reading and writing, though Object.getPrototypeOf() is preferred for reading in modern code.