Skip to main content
← JavaScript Lesson 5 / 5

The Prototype Chain

In JavaScript, objects don't each carry their own copy of every method. Instead they link to a prototype — and when you ask for a property, JS climbs the chain of links until it finds it (or runs out). Pick a property and watch the search walk up.

Look up a property

Pick a property to look up and watch the search climb the chain.

What's really happening

const dog = Object.create(Dog.prototype);
dog.name = "Rex";

dog.bark();   // not on dog — climb to Dog.prototype ✓
dog.eat();    // climb past Dog → Animal.prototype ✓
dog.fly();    // climb to null, never found → undefined

The prototype chain

  1. dog
    the instance
    name
  2. Dog.prototype
    every Dog shares this
    bark
  3. Animal.prototype
    every Animal shares this
    eat describe
  4. Object.prototype
    the root object
    toString hasOwnProperty
  5. null
    end of the chain
    no properties — end of the line

No lookup running yet.