Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Object.prototype.constructor — the constructor property

Object.prototype.constructor is a data property whose initial value is the Object function. Objects usually inherit constructor from a prototype, but it can be shadowed, so it is not a reliable way to identify a type.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

Object.prototype.constructor
object.constructor

Object.prototype.constructor is a data property whose initial value is Object: it holds a function reference, not the function's name. A plain object {} inherits it from Object.prototype; an array normally reads constructor from Array.prototype, where the value is Array.

The property on Object.prototype is writable and configurable but non-enumerable. Assigning item.constructor = String in the example creates an own property that shadows the inherited value. It does not change the object's prototype or turn it into a String instance. An object created with Object.create(null) does not inherit this property.

Do not treat constructor as reliable evidence of an object's type or creation history: the property can be changed or shadowed. Replacing Child.prototype can also cause instances to read an inherited value pointing to a different constructor.

Distinguish this property from the constructor() {} method in a class definition, which initializes instances. Merely reading item.constructor does not call any function. This is part of the ECMAScript standard library, not a Web API; MDN marks it as widely available across browsers.

Examples

const item = {};
console.log(Object.prototype.constructor === Object);
console.log(item.constructor === Object);

item.constructor = String;
console.log(item.constructor === String);
console.log(Object.getPrototypeOf(item) === Object.prototype);
console.log(item instanceof String);
console.log(Object.create(null).constructor === undefined);

Result

true
true
true
true
false
true

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources