Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

JavaScript Object.prototype.isPrototypeOf() method

  • Last Updated : 27 Sep, 2021

The method isPrototypeOf() checks if an object exists in another object’s prototype chain.

Syntax:

prototypeObj.isPrototypeOf(object)
  • object: This is an object, whose prototype chain will be searched.

Return value: A Boolean.

Errors thrown:

A Type Error is thrown if prototypeObj is undefined or null.

Example:

javascript




function obj1() {}
function obj2() {}
 
obj1.prototype = Object.create(obj2.prototype);
const obj3 = new obj1();
console.log(obj1.prototype.isPrototypeOf(obj3));
console.log(obj2.prototype.isPrototypeOf(obj3));

Output:

true
true

Example 2: This example illustrates that C.prototype, B.prototype, A.prototype and Object.prototype exist in the prototype chain for object c:

javascript




function A() {}
function B() {}
function C() {}
 
B.prototype = Object.create(A.prototype);
C.prototype = Object.create(B.prototype);
 
var c = new C();
 
console.log(C.prototype.isPrototypeOf(c));
console.log(B.prototype.isPrototypeOf(c));
console.log(A.prototype.isPrototypeOf(c));
console.log(Object.prototype.isPrototypeOf(c));

Output:

true
true
true
true

Supported Browser:

  • Chrome 1 and above
  • Edge 12 and above
  • Firefox 1 and above
  • Internet Explorer-9 and above
  • Opera 4 and above
  • Safari 3 and above

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!