Monday, November 18, 2024
Google search engine
HomeLanguagesJavascriptJavaScript Object isPrototypeOf() Method

JavaScript Object isPrototypeOf() Method

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

Syntax:

prototypeObj.isPrototypeOf(object)

Parameters: This object accepts a single parameter.

  • object: This is an object, whose prototype chain will be searched.

Return value: This method returns a boolean value.

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

Example: This example shows the basic use of the JavaScript Object.prototype.isPrototypeOf() method.

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);
  
let 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

We have a complete list of Javascript Object Methods, to check those please go through the Javascript Object Complete Reference article.

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
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments