Object.create() is a powerful JavaScript method used to create a new object with a specified prototype object and optional properties. It allows you to set up prototype-based inheritance explicitly.

💡 Why use Object.create()?
It helps create objects that inherit directly from another object, providing a clear and flexible way to set the prototype chain without using constructor functions or classes.
Basic Syntax
Object.create(proto, propertiesObject)
proto: The object which should be the prototype of the newly created object.propertiesObject(optional): An object specifying property descriptors (likevalue,writable,enumerable, etc.).
How it works
The new object inherits all properties and methods from the proto object through the prototype chain.
📌 Deep Dive: Creating an object with a prototype
const person = {
greet() {
return `Hello, I am ${this.name}`;
}
};
const alice = Object.create(person);
alice.name = "Alice";
console.log(alice.greet()); // Hello, I am Alice
Setting properties on the new object
You can define properties with descriptors when creating the object:
📌 Deep Dive: Defining properties with descriptors
const animal = {
speak() {
return `${this.sound}!`;
}
};
const dog = Object.create(animal, {
sound: {
value: "Woof",
writable: true,
enumerable: true,
configurable: true
}
});
console.log(dog.speak()); // Woof
dog.sound = "Bark";
console.log(dog.speak()); // Bark
Bark
⚠️ Important:
If the first argument to Object.create() is null, the created object will have no prototype at all (no inherited properties or methods).
| Feature | Object.create() | Object Literal |
|---|---|---|
| Prototype control | Explicitly sets prototype | Defaults to Object.prototype |
| Inheritance | Allows inheritance from any object | Inherits from Object.prototype |
| Property descriptors | Supports property descriptors on creation | Uses default property descriptors |
💡 Summary
Object.create()creates a new object with the specified prototype.- It allows setting properties with fine-grained control via descriptors.
- It's a clean way to implement prototypal inheritance.
Quick Knowledge Check
Test what you just learned
Question 1 of 2
What argument does Object.create() require to set the prototype of the new object?
Question 2 of 2
What happens if you pass null as the prototype argument to Object.create()?
Loading results...