What is prototypal inheritance in JavaScript?

JavaScript Objects Intermediate 2–3 Yrs3–5 Yrs Conceptual 1 min read

Quick Answer

Every JavaScript object has an internal link to another object — its prototype. When you access a property that isn't on the object, the engine walks up the prototype chain until it finds it or hits null. That's inheritance — objects inherit directly from other objects, not from classes.

In JavaScript objects inherit from other objects, not from classes. Every object has a hidden link to a prototype object, and when you read a property that the object doesn't have, the engine follows that link up the chain until it finds it or runs out. So [].map works because map lives on Array.prototype. The class keyword from ES6 is just a nicer syntax over this — extends wires up the prototype chain and the methods you define go on the prototype, so all instances share one copy.

  • obj.__proto__ (or Object.getPrototypeOf(obj)) is the object's prototype; a function's prototype property is the object that instances created with new will get as their prototype.
  • class syntax (ES6) is sugar over this — extends sets up the prototype chain, methods go on the prototype.
  • Object.create(proto) makes a new object with a specific prototype.
  • Methods are shared via the prototype (one copy), not duplicated per instance.