JavaScript instanceof Operator
JavaScript is not object oriented programming but we can implements some concepts of the object oriented programming in JavaScript.
When we create a class in JavaScript and creates the object of it so we can also check at the run time that the particular object is the instance of the particular class or not.
It simply check the prototype in object’s prototype chain.
It return true if the object is of specific class otherwise return the false.
Syntax
object instanceof ClassName
Let’s we create the class in the JavaScript, It’s nothing new but we can create the class in JavaScript using the function keyword.
function Books() { } var b1 = new Books(); alert(b1 instanceof Books); // return the true var strBooks = "JavaScriptHive"; var myString = new String(); alert(strBooks instanceof String); // returns the false alert(myString instanceof String) //returns the true
see the typeof operator.
Happy Coding. 🙂