·  JavaScript – Syntax – Keywords – instanceof

 

- Info:

  - instanceof keyword returns true if the specified object is of the specified object type.

  - This tutorial is based on http://stackoverflow.com/questions/2449254/what-is-the-instanceof-operator-in-javascript.

 

- Additional Tutorials:

  - Inheritance

 

- Example:

  - Create D\Temp\JavaScript\Test.html

 

    Test.html

    <script>

   

      //CREATE PROTOTYPE.

      function Person(name, age) {

        this.name  = name;

        this.age   = age;

        this.hello = function() { document.write("Hello"); };

      }

   

      //CREATE OBJECT.

      john = new Person("John", 50);

      if (  john instanceof Person)  { document.write("john IS     instanceof Person.<br>"); }

      if (!(john instanceof String)) { document.write("john IS NOT instanceof String.    "); }

   

    </script>