JavaScript TypeError – Invalid ‘instanceof’ operand ‘x’

This JavaScript exception invalid ‘instanceof’ operand occurs if the right operand of the instanceof operator can not be used with a constructor object. It is an object that contains a prototype property and can be called.

Message:

TypeError: invalid 'instanceof' operand "x" (Firefox) 
TypeError: "x" is not a function (Firefox) 
TypeError: Right-hand side of 'instanceof' is not an object (Chrome) 
TypeError: Right-hand side of 'instanceof' is not callable (Chrome)

Error Type:

TypeError

Cause of the error: The right side of the instance operator is not a constructor object.

Example 1: In this example, the right side of instanceof operator is not a constructor object.



HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
"Geeks" instanceof ""; // error here
</script>

chevron_right


Output:

TypeError: Right-hand side of 'instanceof' is not an object

Example 2: In this example, the right side of instanceof operator is not a constructor object.

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
function GFG() {}
var gfg = GFG();   
var x = new GFG();
x instanceof gfg; // error here
</script>

chevron_right


Output:

TypeError: Right-hand side of 'instanceof' is not an object

full-stack-img

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.