Favorites

JavaScript instanceof Operator

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
instanceof
JavaScript Relational OperatorThis operator is supported by all modern browsers.
Updated 28th November 2026

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 Constructor

Example

class Animal {}
class Dog extends Animal {}
const rex = new Dog();
console.log(rex instanceof Dog, rex instanceof Animal, rex instanceof Array);
try { null.x; } catch (e) { console.log(e instanceof TypeError); }
console.log('text' instanceof String);

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.

This operator is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee