JavaScript instanceof Operator

You are Here:

JavaScript instanceof Operator

The instanceof operator returns a Boolean value indicates whether the prototype property of a constructor appears anywhere in the prototype chain of an object.


HTML Online Editor
<!DOCTYPE html> <html> <body> <script> var num = new Number(36); var str = new String("hello"); var bool = new Boolean(true); var arr = [1, 2, 3]; var obj = {bike: "honda", color: "red"}; var txt = ""; txt += "num : "+ (num instanceof Number) + "<br>"; txt += "str : "+ (str instanceof String) + "<br>"; txt += "bool : "+ (bool instanceof Boolean) + "<br>"; txt += "arr : "+ (arr instanceof Array) + "<br>"; txt += "obj : "+ (obj instanceof Object) + "<br>"; document.write(txt); </script> </body> </html>


object instanceof constructor

Parameter Values

objectRequiredThe object to test.
constructorRequiredFunction to test against.

Return Values

trueIf the object is the instance of constructor.
falseIf the object is not the instance of constructor.

More Examples


HTML Online Editor
<!DOCTYPE html> <html> <body> <script> function bike(brand, model, color){ this.brand = brand; this.model = model; this.color = color; } var honda = new bike("Honda", "CB1000R", "Red"); document.write(honda instanceof bike); </script> </body> </html>


Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author