JavaScript instanceof Operator
The instanceof operator checks whether an object was created by a given class or constructor, by looking at its prototype chain.
Description
The instanceof operator tests whether the prototype of a constructor appears anywhere in an object's prototype chain, meaning the object is an instance of that class or one of its subclasses. It's commonly used to tell error types apart in a catch block.
It doesn't work for primitives ('a' instanceof String is false) and can fail across iframes, since each has its own constructors; for arrays, Array.isArray() is more reliable.
Classes can customize the check with a static Symbol.hasInstance method, which some libraries use. Because instanceof looks at the prototype chain, objects created with Object.create(null) aren't instances of Object, and changing an object's prototype changes the result. For plain data, checking for the properties you need is often more flexible than checking its class.
Properties
- Operator
instanceof- Category
- Relational
- Precedence
- 9 (1 is lowest, 18 is highest)
- Associativity
- left-to-right
Syntax
object instanceof ConstructorExample
Browser Support
The following information will show you the current browser support for the instanceof operator. Hover over a browser icon to see the version that first introduced support for this operator.
Desktop





Tablets & Mobile





