Prototypes &
Prototype Chain
Discover how JavaScript objects inherit properties and methods through an invisible chain: the foundation of object-oriented JavaScript.
What Is a JavaScript Object?
In JavaScript, an object is a collection of key-value pairs. Keys are strings (called properties), and values can be any data type: numbers, strings, functions, or even other objects.
What Is a Prototype?
A prototype is a regular JavaScript object from which other objects inherit properties and methods. Think of it as a blueprint parent: anything the parent has, its children can access automatically.
Why Do Prototypes Matter?
The Prototype Chain
When you access a property, JavaScript follows a lookup chain: it checks the object itself, then its prototype, then that object's prototype, and so on until it reaches null.
The Chain Ends at null
Object.prototype sits at the top of every prototype chain. Its own prototype is null: the chain always terminates. If a property isn't found anywhere in the chain, JavaScript returns undefined.
__proto__ vs .prototype
These two are the most confused concepts in JavaScript prototypes. They are related but serve very different purposes.
| __proto__ | .prototype | |
|---|---|---|
| Lives on | Every object | Only on functions |
| Purpose | Points to this object's prototype | Becomes the prototype of objects created by this function |
| Example | myDog.__proto__ | Dog.prototype |
| Preferred API | Object.getPrototypeOf() | Direct property access |
How new Wires the Chain
When you call a function with the new keyword, JavaScript performs four hidden steps to connect the prototype chain.
How to Trace the Chain
Follow these steps to trace any prototype chain and understand property lookups.
Example 1: Basic Chain
Example 2: Property Shadowing
Example 3: Object.create()
Object.create() lets you build a prototype chain without constructor functions.
Classes Are Syntactic Sugar
ES6 class syntax looks like classical inheritance, but under the hood it's still prototypes. The class keyword doesn't create a new mechanism: it wraps the same constructor + prototype pattern in cleaner syntax.
Own vs Inherited Properties
JavaScript gives you tools to distinguish between properties an object owns directly and properties it inherits from the chain.
Common Mistakes
Summary at a Glance
| Concept | What It Does | Key Detail |
|---|---|---|
| Prototype | Object that others inherit from | Every object has one (except null) |
| Prototype Chain | Linked list of prototypes | Ends at Object.prototype → null |
| __proto__ | Link to the actual prototype | Present on every object |
| .prototype | Blueprint for instances | Only on constructor functions |
| new keyword | Creates + links objects | Sets __proto__ = Fn.prototype |
| Object.create() | Manual chain linking | No constructor needed |
Question 1 of 5
What happens when you access a property that doesn't exist on an object?
Question 2 of 5
What is the difference between __proto__ and .prototype?
Question 3 of 5
Given the code below, what does buddy.hasOwnProperty("bark") return?
function Dog(name) {
this.name = name;
}
Dog.prototype.bark = function() {
return "Woof!";
};
const buddy = new Dog("Buddy");
Question 4 of 5
What sits at the very top of every prototype chain?
Question 5 of 5
ES6 class syntax in JavaScript introduces: