← Back to Roadmap

Prototypes & Prototypal Inheritance

Hard

In plain terms

Every object has a prototype. When a property is not found, JavaScript looks up the prototype chain. Object.create() creates with a specified prototype. Understanding prototypes is key to JavaScript.

What you need to know

  • Prototype chain
  • Object.create()
  • __proto__ and prototype

Try it yourself

Copy the code below and run it in your browser console or a code editor:

const parent = { greet() { return 'Hi'; } };
const child = Object.create(parent);
child.greet();  // "Hi"

function Foo() {}
Foo.prototype.bar = function() {};
const f = new Foo();
Object.getPrototypeOf(f) === Foo.prototype;  // true

Learn more

Dive deeper with these trusted resources: