Difference Btwn instanceOf and isPrototypeOf

While I am doing some revision to gain a better understanding of what I am dealing with. I have found myself asking the same question over and over again.

Now that everything is beginning to click, I found “methods” that appears to have the same function and I am having some trouble attempting to find their difference.

  1. From my understanding an (instanceof) method is simply asking whether the object is created from object.
  2. The same question appears to being asked by (isPrototypeOf) method.

Q1) What is the difference between those two methods?
Q2) In the code below, when (isPrototypeOf) is being used to check beagal, How come the word prototype is to be excluded?

Q2)(Possible answer) I suspect it’s because beagle is the final object to be created from the Chain of Objects.

  **Your code so far**

function Dog(name) {
this.name = name;
}

let beagle = new Dog("Snoopy");

Dog.prototype.isPrototypeOf(beagle);  // yields true

console.log(beagle instanceof Dog) //yields true
console.log(Dog.prototype.isPrototypeOf(beagle.prototype)); // yields false
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.87 Safari/537.36

Challenge: Understand the Prototype Chain

Link to the challenge:

I suggest reading this stackoverflow question, which is the same thing you asked .

The main difference between instanceof and isPrototypeOf is that instanceof can make a check for an object that has no constructor.
Whereas isPrototypeOf() method is used to test whether an object is present on the prototype chain of another object.

I suggest reading this resource too.

Hope this helped.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.