JavaScript Object isPrototypeOf() method
determines if this object exists in another object's prototype chain

Object.isPrototypeOf() method determines if this object exists in another object's prototype chain.

syntax

prototypeObj.isPrototypeOf(obj)  ↴

prototypeObj The object against which we want to compare our selected object's obj prototype.

obj The object whose prototype chain will be searched.

Object.isPrototypeOf() method returns true if prototypeObj lies in the prototype chain of obj.

Object.isPrototypeOf() method returns false if prototypeObj is not the prototype of obj, or if obj is not an object itself.

All objects that inherit from Object.prototype (that is, all except null-prototype objects) inherit the Object.isPrototypeOf() method.

This method allows you to check whether or not the object exists within another object's prototype chain.

TypeError is thrown if prototypeObj is undefined or null (because it can't be converted to an object).

Object.isPrototypeOf() differs from the instanceof operator. In the expression ↴

object instanceof AFunction

the object prototype chain is checked against AFunction.prototype, not against AFunction itself.

isPrototypeOf() method - along with the instanceof operator - comes in particularly handy if you have code that can only function when dealing with objects descended from a specific prototype chain; e.g., to guarantee that certain methods or properties will be present on that object.

All objects that inherit from Object.prototype inherit the isPrototypeOf() and toString() methods among others.

code

// create 3 new objects:

function One() {}

function Two() {}

function Three() {}

// create 2 new objects from our existing functions:

Two.prototype = Object.create(One.prototype)

Three.prototype = Object.create(Two.prototype)

// create new object from function Three():

let Four = new Three()

// create 2 new objects (independent from above):

function Five() {}

function Six() {}

syntax description
check if object exists in another object's prototype chain
protoObj.isPrototypeOf(obj)