What is Object.create()?
Object.create(proto) makes a new object with the prototype you specify, giving direct control over prototypal inheritance.
Custom prototype — the new object inherits from proto.
Object.create(null) — a "bare" object with no prototype, ideal as a clean dictionary/map.
In short: it links objects directly, without constructors or classes — pure prototypal inheritance.
// Basic usage
const animal = {
speak() { return `${this.name} makes a sound`; }
};
const dog = Object.create(animal);
dog.name = 'Rex';
console.log(dog.speak()); // 'Rex makes a sound'
console.log(Object.getPrototypeOf(dog) === animal); // true
// Prototype chain
const puppy = Object.create(dog);
puppy.name = 'Buddy';
console.log(puppy.speak()); // 'Buddy makes a sound' (inherited from animal)
// Object with no prototype (pure dictionary)
const dict = Object.create(null);
dict.key = 'value';
console.log(dict.toString); // undefined (no prototype!)
// Safe from prototype pollution
// With property descriptors
const config = Object.create(null, {
debug: { value: true, writable: false, enumerable: true },
version: { value: '1.0', writable: false, enumerable: true }
});
// config.debug = false; // TypeError in strict modeObject.create(animal) creates a new object with animal as its prototype — dog inherits speak(). Prototype chain: puppy → dog → animal.
Object.create(null) creates a prototype-less object — no inherited methods (pure dictionary, safe from prototype pollution). Property descriptors in the second argument define non-writable, non-configurable properties.
Know three use cases: setting up prototype chains (explicit inheritance), Object.create(null) for pure dictionaries (no prototype pollution), and property descriptors for controlled properties. Compare to class/constructor approaches.
Object.create(null) for Maps/caches is a practical security pattern.