Object.getPrototypeOf()

TheObject.getPrototypeOf()static method returns the prototype (i.e. the value of the internal[[Prototype]]property) of the specified object.

Try it

Syntax

js
Object.getPrototypeOf(obj)

Parameters

obj

The object whose prototype is to be returned.

Return value

The prototype of the given object, which may benull.

Examples

Using getPrototypeOf

js
constproto={};
constobj=Object.create(proto);
Object.getPrototypeOf(obj)===proto;// true

Non-object coercion

In ES5, it will throw aTypeErrorexception if theobj parameter isn't an object. In ES2015, the parameter will be coerced to an Object.

js
Object.getPrototypeOf("foo");
// TypeError: "foo" is not an object (ES5 code)
Object.getPrototypeOf("foo");
// String.prototype (ES2015 code)

Specifications

Specification
ECMAScript Language Specification
#sec-object.getprototypeof

Browser compatibility

BCD tables only load in the browser

See also