JavaScript instanceof operator

Understand the basics of JavaScript instanceof operator

JavaScriptinstanceofIf the first operand is an instance of the object passed on the right or one of its ancestors in the prototype chain, then operator returns true.

In this example, you can seemyCarFiesta class object responds to trueinstanceof FiestaAnd rightinstanceOf Car, Because Carnival expanded Car:

class Car {}
class Fiesta extends Car {}

const myCar = new Fiesta() myCar instanceof Fiesta //true myCar instanceof Car //true

Download mine for freeJavaScript beginner's manual

More js tutorials: