Skip to content
Sahil Durgia/ full-stack
2 min readJavaScript

Prototypal Inheritance: JavaScript's Most Misunderstood Feature

JavaScript doesn't have classes underneath the class keyword — it has objects linked to other objects. Here's what that actually means and why it matters.

JavaScriptprototypesOOP

JavaScript added a `class` keyword in ES6, and it's easy to come away thinking JavaScript got classical, Java-style inheritance. It didn't — `class` is syntax sitting on top of the same mechanism that was always there: prototypal inheritance, where objects inherit directly from other objects, not from a blueprint.

What actually happens when you access a property

Every object has an internal link to another object — its prototype. When you access a property that doesn't exist directly on the object, the engine walks up the prototype chain, checking each linked object in turn, until it finds the property or runs out of chain (at which point you get `undefined`).

const animal = { speak() { return `${this.name} makes a sound`; } };
const dog = Object.create(animal);
dog.name = 'Rex';
dog.speak(); // 'Rex makes a sound' — speak() isn't on dog, found via the prototype chain

What `class` actually compiles down to

class Animal {
  constructor(name) { this.name = name; }
  speak() { return `${this.name} makes a sound`; }
}
// speak() lives on Animal.prototype, exactly like the Object.create example above

A method defined in a `class` body isn't copied onto every instance — it's placed once on the shared prototype object, and every instance finds it via the same chain-walking lookup as the plain-object version. `class` is real, useful syntax — it's just describing the same underlying mechanism, not a different one.

Why this is worth actually knowing

It explains why changing a method on a prototype after instances already exist changes behavior for all of them (they share the same prototype object, not a copy). It explains `Object.create(null)` as a way to make an object with no prototype chain at all, useful for a plain lookup map with zero inherited properties to accidentally collide with. And it's the difference between memorizing `class` syntax and actually understanding what JavaScript is doing underneath it.

Keep reading
Next: sync vs async JavaScript

Part 7 of the JavaScript fundamentals series.