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>
<html>
<body>
   
   <script>
      function myFun(x, y, z) {
         this.x = x;
         this.y = y;
         this.z = z;
      }
      const v = new myFun(10, 20, 30);
      document.write(v instanceof myFun);
   </script>
   
</body>
</html>
Output

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 »