creation

Object.create

Creates a new object with the specified prototype and optional property descriptors. Pass null to create an object with no prototype at all.

Object.create(proto, propsObject?)

Parameters

Parameter Purpose
proto The prototype for the new object, or null
propsObject Optional map of property names to descriptors (like defineProperties)
returns A new object

Examples

const proto = { greet() { return 'hi'; } };
const obj = Object.create(proto);
console.log(obj.greet());

Logs 'hi' — greet is inherited

const bare = Object.create(null);
console.log(bare.toString);

Logs undefined — no Object.prototype methods

const o = Object.create({}, { x: { value: 1, enumerable: true } });
console.log(o.x);

Logs 1

const clone = Object.create(Object.getPrototypeOf(orig = { a: 1 }), Object.getOwnPropertyDescriptors(orig));
console.log(clone.a);

Logs 1 — creates a shallow clone preserving prototype and descriptors

Gotcha

The second argument uses property DESCRIPTORS (like defineProperties), not plain values — properties default to non-enumerable, non-writable, non-configurable if not specified. Object.create(null) creates a 'dictionary' object safe for arbitrary keys.

Related methods

← All JS Object methods · Array methods · Spread vs rest