JavaScript instanceof Operator

instanceof Operator

instanceof is used to check if the given value is of the specified data type

instanceof operator takes a value/variable as left operand, the type as second operand, and returns true if the data type of the value is same as that of the specified data type, or false otherwise.

a instanceof String
"hello world" instanceof String


1. Check if new String("hello world") is an instance of String.

a = new String("hello world");
output = a instanceof String;