Script Valley
JavaScript: The Complete Language
Objects, Arrays, and DestructuringLesson 3.4

Prototypes and prototype chain in JavaScript

prototype chain, Object.prototype, __proto__, Object.create, prototype-based inheritance, hasOwnProperty, prototype vs class, property lookup order

How JavaScript Implements Inheritance

Every JavaScript object has an internal link to another object called its prototype. When you access a property, JavaScript searches the object itself, then walks the prototype chain upward until it finds the property or reaches null. This mechanism is how all JavaScript inheritance works — classes included.

Prototype Lookup in Action

const animal = { breathes: true };
const dog = Object.create(animal);
dog.bark = function() { return "Woof"; };

dog.bark()     // "Woof"             — own property
dog.breathes   // true               — found on prototype
dog.toString() // "[object Object]"  — found on Object.prototype
dog.missing    // undefined          — not found anywhere

Checking Own vs Inherited Properties

dog.hasOwnProperty("bark")     // true
dog.hasOwnProperty("breathes") // false — inherited
Object.hasOwn(dog, "bark")     // true — modern equivalent

Constructor Functions and .prototype

function Vehicle(type) {
  this.type = type;
}
Vehicle.prototype.describe = function() {
  return `I am a ${this.type}`;
};

const car = new Vehicle("car");
car.describe(); // "I am a car"
// describe is on Vehicle.prototype, shared by all instances

Why This Matters

The class syntax introduced in ES6 is syntactic sugar over this prototype system — it does not create a fundamentally different inheritance model. Understanding prototypes means you truly understand what classes compile to, and why method lookup works the way it does in every JavaScript runtime.

Up next

ES6 classes in JavaScript: syntax, inheritance, and pitfalls

Sign in to track progress