Prototype chaining

Prototype chaining in JavaScript is a mechanism used to implement inheritance by linking objects through their prototypes. If a property or method is not found on an object, the JavaScript engine looks up the chain via the object's [[Prototype]]
(accessible using Object.getPrototypeOf(obj)
or the __proto__
property).
When using constructor functions, methods and properties meant to be shared are added to the constructor’s prototype object (e.g., ConstructorFunction.prototype
).
So:
obj.__proto__
orObject.getPrototypeOf(obj)
gives the prototype of the object instanceConstructorFunction.prototype
is the object that will become the prototype of all instances created withnew ConstructorFunction()
✅ Prototype Chaining in JavaScript (Interview-Style Explanation)
Prototype chaining is the mechanism by which JavaScript objects inherit properties and methods from other objects. Every object in JavaScript has an internal link to another object called its [[Prototype]]
. This chain continues until it reaches null
.
This is how inheritance is implemented in JavaScript — it's how one object can "look up" properties or methods defined on another.
📌 Key Interview Points
Each object has a
[[Prototype]]
, accessible viaObject.getPrototypeOf(obj)
orobj.__proto__
.Constructor functions have a
.prototype
property — this is used to assign the prototype of instances created withnew
.When accessing a property, JavaScript checks the object first, then follows the prototype chain if the property isn't found.
function Animal(name) {
this.name = name;
}
Animal.prototype.sayHello = function () {
return `Hi, I'm ${this.name}`;
};
function Dog(name, breed) {
Animal.call(this, name); // Call parent constructor
this.breed = breed;
}
// Set up inheritance via prototype chain
Dog.prototype = Object.create(Animal.prototype);
Dog.prototype.constructor = Dog;
Dog.prototype.bark = function () {
return `${this.name} says Woof!`;
};
const dog = new Dog("Buddy", "Golden Retriever");
console.log(dog.bark()); // Buddy says Woof!
console.log(dog.sayHello()); // Hi, I'm Buddy
🧠 Summary of Key Points
Concept | Accessed By | Purpose |
Instance’s prototype | Object.getPrototypeOf(obj) or obj.__proto__ | Shows what object the instance inherits from |
Constructor’s prototype | Constructor.prototype | Where shared methods are defined |
Prototype chaining | Follows the [[Prototype]] chain | Enables inheritance in JS |
Subscribe to my newsletter
Read articles from Sagar Kumar Jha directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Sagar Kumar Jha
Sagar Kumar Jha
Softwares are art and I am an artist