JS Built-ins
Prototypesbeginner

Prototypes β€” instanceof operator

πŸ“– Usage Example
class Animal {}
const a = new Animal();
a instanceof Animal; // true
a instanceof Object; // true

instanceof checks if an object was created by a class or its ancestors.

Testing Instance Relationships

The instanceof operator checks if an object is an instance of a class or constructor function. It returns true if the object's prototype chain includes the constructor's prototype.

Challenge: Use instanceof to verify class instances and understand the instance relationship.

πŸ’‘ Hints (2)
  • β€’ instanceof checks the prototype chain
  • β€’ It returns true for both direct and inherited classes