instanceof operator code example
Example 1: instanceof javascript
var color = "red";
var color2 = {};
color instanceof String // will return true
color2 instanceof Object // will return true
Example 2: Explain about instanceof operator in java
An instanceof in Java is a comparison operator which, given an object instance,
checks whether that instance is of a specified type (class/sub-class/interface)
or not. Just like other comparison operators, it returns true or false.
Comparing any object instance with a null type through instanceof operator
returns a false.
Instanceof operator is used to test the object is of which type.
Syntax : instanceof
Instanceof returns true if reference expression is subtype of destination type.
Instanceof returns false if reference expression is null.