JavaScript instanceof Operator2 Mar 2025 | 4 min read JavaScript instanceof operator will find the object type at the time of runtime. The outcome we can expect can be Boolean values that are either true or false which are based on the inputs we gave and the objects that are included. Syntax:ParametersObjectName: The name of the object. ObjectType: It determines the object's type which is used for testing. Why is an instanceof necessary in JavaScript?Instanceof operator in JavaScript is necessary due to when we declare XYZ as a variable that represents many user-defined datatypes it can be used for many purposes like integers, characters, arrays, and many other datatypes. So, this operator will help us to identify the particular datatype for which an object is linked. Example 1: The Instanceof Operator and InheritanceWe will discuss some of the examples related to instanceof operator here: Code Output ![]() Justification
Example 2: Symbol.hasInstanceJust like how we can employ the instanceof operator to ascertain if an object is a class instance, we can use Symbol.hasInstance to check if a class includes an object instance. Symbol.hasInstance will return true if an object exists in the class; otherwise, it will return false. Code Output ![]() Justification
Example 3: Making use of String with instanceofWe'll see how the instanceof operator handles String objects in this example. Code Output ![]() Justification
Example 4: Making use of Date and instanceofWe will examine the behavior of the instanceof operator when working with Date objects in this example. Code Output ![]() Justification
Example 5: Using Object.create() to Create ObjectsWe will examine the behavior of the instanceof operator in this example when we use the Object.create() method to create the object. Code Output ![]() Example 6: Not an instanceofIn this example, we will learn how to check whether an object is an instance of a class or not by using the Not operator in conjunction with the instanceof operator. Code Output ![]() Justification
In summaryFrom the article, we learned the following:
Next TopicgroupBy() in JavaScript |
We request you to subscribe our newsletter for upcoming updates.

We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India





