Prototype inheritance is JavaScript’s mechanism where objects delegate property access to other objects through a prototype chain.
Every JavaScript object has an internal property called [[Prototype]] (accessible via __proto__ or Object.getPrototypeOf()).
When you access a property:
nullThis delegation mechanism is prototype inheritance.
const person = {greet() {console.log("Hello");}};const user = {name: "Alice"};Object.setPrototypeOf(user, person);user.greet(); // "Hello"
user does not have greetuser.__proto__ → persongreet and executes itThat lookup path is the prototype chain.
When using constructor functions, JavaScript automatically links objects to a prototype.
function User(name) {this.name = name;}User.prototype.sayHi = function () {console.log(`Hi, I'm ${this.name}`);};const u1 = new User("Bob");u1.sayHi();
Prototype chain:
u1 → User.prototype → Object.prototype → null
✔️ Methods are shared ✔️ Memory efficient ✔️ Dynamic inheritance
Object.prototype (The Root)Almost all objects eventually inherit from Object.prototype.
u1.toString(); // from Object.prototype
This is why methods like toString, hasOwnProperty, and valueOf are available everywhere.
Prototype inheritance enables: