inspection

Object.getPrototypeOf

Returns the prototype (i.e. the internal [[Prototype]]) of the specified object, or null if it has none. Preferred over the legacy __proto__ accessor.

Object.getPrototypeOf(obj)

Parameters

Parameter Purpose
obj The object whose prototype is to be returned
returns The prototype object or null

Examples

console.log(Object.getPrototypeOf({}) === Object.prototype);

Logs true

console.log(Object.getPrototypeOf([]) === Array.prototype);

Logs true

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

Logs null — bare object has no prototype

class Animal {}
class Dog extends Animal {}
console.log(Object.getPrototypeOf(Dog.prototype) === Animal.prototype);

Logs true — confirms the class inheritance chain

Gotcha

For primitives it returns the prototype of the boxed wrapper (e.g. String.prototype for a string). Prefer this over the legacy `__proto__` property, which is deprecated for reads and writes.

Related methods

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