JavaScript instanceof

The JavaScript instanceof operator is used to check whether the prototype property of a constructor appears in the prototype chain of an object or not. For example:

HTML with JavaScript Code
<!DOCTYPE html>

   <p id="xyz"></p>
      function myFun(x, y, z) {
         this.x = x;
         this.y = y;
         this.z = z;
      const v = new myFun(10, 20, 30);
      document.getElementById("xyz").innerHTML = v instanceof myFun;

JavaScript instanceof Syntax

The syntax of instanceof operator in JavaScript, is:

object instanceof constructor

It returns boolean value (true/false).

JavaScript Online Test

« Previous Tutorial JavaScript Example »

Follow/Like Us on Facebook

Subscribe Us on YouTube