Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

JavaScript · Function

Object.getPrototypeOf

Object.getPrototypeOf() returns the internal [[Prototype]] of a value. Its result is an object or null; modern JavaScript coerces primitive arguments to wrapper objects before retrieving the prototype.

How it works

Object.getPrototypeOf(obj) retrieves obj's internal [[Prototype]] value. The result is either an object or null; in current JavaScript, a primitive argument is converted to its corresponding wrapper object before the prototype is read.

Syntax

Object.getPrototypeOf(obj)

Parameters

NameTypeDescription
objObjectThe value whose prototype is returned.

Returns

The prototype of the supplied value, which may be null.

Key points

  • It is a static Object method that returns the specified object's prototype.
  • The returned value corresponds to the object's internal [[Prototype]].
  • Its only parameter is the value whose prototype should be inspected.
  • The result can be an object or null.
  • Call the function with one argument: Object.getPrototypeOf(obj).
  • It can verify that an object was created with a particular prototype.

Common mistakes

  • Primitive arguments are coerced to objects in ES2015+, so Object.getPrototypeOf("foo") returns String.prototype rather than throwing.
  • Handle null as a valid result, especially when inspecting Object.prototype or objects created with a null prototype.

Example: Read an object's prototype

const prototype = { greet() { return "hello"; } };
const object = Object.create(prototype);

console.log(Object.getPrototypeOf(object) === prototype); // true
console.log(Object.getPrototypeOf(Object.prototype)); // null

Creates an object with a chosen prototype, then retrieves that prototype and confirms the end of the standard object chain.

When to use it

Inspect inheritance

Check whether an object inherits from a particular prototype.

Traverse the prototype chain

Walk an object's prototype chain until the result is null.

Validate object construction

Verify the prototype assigned by Object.create() or a constructor.

  • Object.create()
  • Object.setPrototypeOf()
  • Reflect.getPrototypeOf()
  • Object.prototype.__proto__

Source: Object.getPrototypeOf () - JavaScript | MDN. Checked 2026-10-15.