Course contentsShow
← JavaScript
Lesson 699 of 2,72317. Prototypes and InheritanceFree lesson

Object.getPrototypeOf()

Using the standard method to retrieve an object's prototype safely.

Object.getPrototypeOf()

You'll learn how to safely retrieve an object's prototype using JavaScript's standard built-in method.

What is Object.getPrototypeOf()?

Object.getPrototypeOf() is the official, safe way to access an object's prototype. It returns the internal prototype (the object from which your object inherits properties) of the specified object.

Think of it like asking "Who is this object's parent?" — the method tells you exactly which object is serving as the template or blueprint from which your object inherits.

Why Use It?

You've learned that prototypes form a chain — objects can inherit from other objects. Object.getPrototypeOf() lets you inspect that chain programmatically, which is useful for:

  • Understanding inheritance relationships
  • Debugging prototype issues
  • Building advanced object systems

Basic Usage

const parent = { species: 'animal' };
const child = Object.create(parent);

const prototype = Object.getPrototypeOf(child);
console.log(prototype === parent); // true

The method takes one argument (the object to inspect) and returns its prototype.

Common Scenarios

// Check what regular objects inherit from
const obj = {};
console.log(Object.getPrototypeOf(obj) === Object.prototype); // true

// Arrays have their own prototype
const arr = [];
console.log(Object.getPrototypeOf(arr) === Array.prototype); // true

// You can chain the calls to walk up the prototype chain
const grandparent = Object.getPrototypeOf(parent);
console.log(grandparent === Object.prototype); // true

Key Takeaway: Object.getPrototypeOf() is the standard, reliable method to inspect an object's prototype, returning the object from which it inherits properties.