01 / 21

Object.create
Prototypal Inheritance

Learn how JavaScript objects can inherit properties from other objects using Object.create: the foundation of prototypal inheritance.

JavaScript

What is an Object in JavaScript?

An object is a collection of key-value pairs. Each key is called a property, and its value can be any data type: a string, number, array, function, or even another object.

const animal = { type: "mammal", legs: 4, speak() { return "..."; } };

The Prototype Chain

Every JavaScript object has a hidden link called [[Prototype]]. When you access a property that doesn't exist on an object, JavaScript follows the chain upward to the prototype, searching until it finds the property or reaches the end.

dog name: "Rex" animal legs: 4, speak() null [[Prototype]] [[Prototype]]

Why Object.create?

JavaScript provides several ways to create objects. Object.create is unique because it lets you explicitly set the prototype of a new object, giving you fine-grained control over inheritance.

Direct
You choose exactly which object becomes the prototype: no hidden surprises.
Lightweight
No constructor function needed. No new keyword. Just one clean call.
Foundational
Understanding it unlocks how class syntax and the entire prototype system work under the hood.

The Syntax of Object.create

const child = Object.create(proto);
proto
The object that will become the new object's [[Prototype]]. Can be any object or null.
child
A brand-new, empty object whose prototype is linked to proto.

The Core Rule

1
Object.create(proto) creates a new empty object.
2
It sets that object's internal [[Prototype]] to point at proto.
3
The child inherits all properties and methods from proto via the prototype chain.
4
Setting a property on the child does not modify the prototype: it creates an own property on the child.

How the Link Works

vehicle (prototype) wheels: 4 engine: true start() { ... } car (child) brand: "Toyota" [[Prototype]] → vehicle const car = Object . create (vehicle); car.wheels → 4 (inherited) car.brand → "Toyota" (own property)

Object.create vs new Keyword

Object.create new Constructor()
Mechanism Sets prototype directly Calls a constructor function
Constructor needed? No Yes
Runs initializer code? No Yes
Result Empty object + prototype link Object with own properties set
Use case Pure inheritance, composition Creating instances from a blueprint

How to Apply It Step by Step

1
Define a prototype object with the shared properties and methods you want to reuse.
2
Call Object.create(proto) to make a new object linked to that prototype.
3
Add own properties to the new child object for its unique data.
4
Access inherited properties on the child: JavaScript will look up the chain automatically.
5
Verify with Object.getPrototypeOf(child) to confirm the link is correct.

Example 1: Basic Inheritance

const animal = { alive: true, breathe() { return "inhale... exhale..."; } }; const cat = Object.create(animal); cat.name = "Whiskers"; console.log(cat.name); // "Whiskers" (own) console.log(cat.alive); // true (inherited) console.log(cat.breathe()); // "inhale... exhale..."

Example 2: Overriding Inherited Properties

const shape = { color: "red", describe() { return "I am a " + this.color + " shape"; } }; const circle = Object.create(shape); circle.color = "blue"; // own property shadows inherited circle.radius = 10; console.log(circle.describe()); // "I am a blue shape" console.log(shape.color); // "red" (unchanged!)

Example 3: Multi-Level Chain

const base = { role: "entity" }; const player = Object.create(base); player.health = 100; const warrior = Object.create(player); warrior.weapon = "sword"; console.log(warrior.weapon); // "sword" (own) console.log(warrior.health); // 100 (from player) console.log(warrior.role); // "entity" (from base)
base player warrior [[Proto]] [[Proto]]

Special Case: Object.create(null)

Passing null as the prototype creates a truly empty object with no prototype at all. It won't inherit toString, hasOwnProperty, or any other built-in method.

const dict = Object.create(null); dict.hello = "world"; console.log(dict.hello); // "world" console.log(dict.toString); // undefined! console.log("hello" in dict); // true console.log("toString" in dict); // false

Own vs Inherited Properties

proto greet() { ... } lang: "en" version: 1 child name: "Ada" greet → inherited lang → inherited child.hasOwnProperty("name") true child.hasOwnProperty("greet") false "greet" in child true

Common Mistakes

✕ Forgetting it returns empty
Object.create doesn't copy properties. The child starts empty: you must add own properties yourself.
✕ Mutating shared references
If the prototype has an array or object, the child shares that same reference. Pushing to it affects all children.
✕ Confusing with Object.assign
Object.assign copies properties. Object.create links prototypes. They solve different problems.

Summary Comparison

Method What it does Result
Object.create(proto) Links new object's [[Prototype]] to proto Empty object + inheritance
Object.assign(target, src) Copies own enumerable properties from src to target Flat copy, no prototype link
{ ...spread } Shallow copies own properties into a new literal Flat copy, no prototype link
new Constructor() Calls constructor, links to Constructor.prototype Initialized instance

Question 1 of 5

What does Object.create(proto) return?

Question 2 of 5

After running the code above, what is the value of base.x?

Question 3 of 5

What is the result of Object.create(null)?

Question 4 of 5

Which expression correctly checks if greet is an own property of obj?

Question 5 of 5

How does Object.create differ from Object.assign?