JS: Object.prototype.isPrototypeOf

By Xah Lee. Date: . Last updated: .
objA.isPrototypeOf(objB)
  • Return true if objA is in Prototype Chain of objB. Else false.
  • If objA is objB, return false
// example of isPrototypeOf

const xaa = {};
const xbb = {};

// make xaa the parent of xbb
Object.setPrototypeOf(xbb, xaa);

console.log(xaa.isPrototypeOf(xbb));
// isPrototypeOf returns true for grand parents too

const xt1 = {};
const xt2 = Object.create(xt1);
const xt3 = Object.create(xt2);
const xt4 = Object.create(xt3);

console.log(xt1.isPrototypeOf(xt4));
// example of isPrototypeOf on same objects
const xx = {};
console.log(xx.isPrototypeOf(xx) === false);

JavaScript, Object and Inheritance