← All tutorials

GoCareerGo Tutorials

JavaScript Tutorial

Variables to closures, promises, the DOM and OOP — a complete JS reference.

Prototypes and Prototype Chain

Every JS object has a hidden link to another object (its prototype) — this chain is how JS implements inheritance.

const animal = { eats: true };
const rabbit = Object.create(animal);
rabbit.jumps = true;

rabbit.eats;  // true — found on the prototype chain
rabbit.hasOwnProperty('eats'); // false — inherited, not own
  • Property lookups walk up the prototype chain until found or reaching null
  • Array.prototype and Object.prototype hold the built-in array/object methods
  • classes are prototype-based inheritance with nicer syntax underneath