Instanceof operator
The instanceof operator tests whether an object or reference is compatible with a specified runtime type or constructor according to the programming language’s rules.
Secrets of the JavaScript Ninja, Second Edition
A JavaScript operator that tests whether an object was created by, or inherits from, a particular constructor via its prototype chain.
- How it is used
- Tests whether an object participates in a constructor’s prototype-based inheritance chain.
- How deep it goes
- Works through prototype-chain matching and shows how replacing a constructor’s prototype reverses an existing object’s result.
- Examples
- Contrasts copied methods with inherited prototypes and tests an existing instance before and after prototype replacement.
- What you can do after
- Diagnose/debug with it: explain a surprising type-check result by inspecting the constructor’s current prototype and the object’s chain.
Read how Secrets of the JavaScript Ninja, Second Edition explains instanceof operator →
100 Java Mistakes and How to Avoid Them
- How it is used
- Guards downcasts and dispatches runtime-type-specific behavior while preventing overlapping conditional branches.
- How deep it goes
- Explains subtype matching through branch-order failures and contrasts it with exact runtime-class comparisons.
- Examples
- Uses BigInteger and BigDecimal conversion, date conversion, ArrayList checks, and Calendar instances.
- What you can do after
- Diagnose/debug with it by finding unreachable type branches and choosing subclass-compatible versus exact-class tests.
Read how 100 Java Mistakes and How to Avoid Them explains instanceof operator →
Also covered in
- Essential TypeScript 5, Third Edition
- Secrets of the JavaScript Ninja, Third EditionIn early access (MEAP)
- Pro Angular 16
- Vanilla WebIn early access (MEAP)
What to know first
- any typeThe any type is a TypeScript type that permits values to be treated as having essentially any type, largely disabling static type checking for them.
- assertionA software assertion is an executable check of an expected condition or property that signals failure when the check does not hold.
- compile-time errorA compile-time error is a violation or failure detected during compilation or static checking that prevents source code from being successfully translated into a program representation.
- new keywordIn JavaScript, new is an operator that creates an object instance by invoking a constructable function or class as its constructor.
Related concepts
- prototype chainuses · A prototype chain is the linked sequence of JavaScript prototype objects consulted during property lookup when an object lacks the requested property itself.
- pattern matchingused by · Pattern matching is the process of comparing values or input with specified patterns to identify matches, classify data, or select corresponding behavior.
- classuses · A class is a programming-language construct that defines a type’s structure and behavior and provides a basis for creating or representing objects.
- interfacecontrasts with · An interface is a contract or boundary that specifies the operations, members, or data shape a type or component exposes, without prescribing its complete implementation.
- condition dominanceuses · Condition dominance is a control-flow relationship in which one condition can be true only when another condition is also true, making the dominated branch unreachable when tested afterward.
- getClasscontrasts with · getClass is the Java Object method that returns the runtime class object of the instance on which it is invoked.
Questions about instanceof operator
What is instanceof operator?
The instanceof operator tests whether an object or reference is compatible with a specified runtime type or constructor according to the programming language’s rules.
Which Manning books explain instanceof operator?
Secrets of the JavaScript Ninja, Second Edition and 100 Java Mistakes and How to Avoid Them.
What should I know before learning instanceof operator?
Manning books that teach instanceof operator usually introduce any type, assertion, compile-time error and new keyword first.
What is the difference between instanceof operator and interface?
The instanceof operator tests whether an object or reference is compatible with a specified runtime type or constructor according to the programming language’s rules. An interface is a contract or boundary that specifies the operations, members, or data shape a type or component exposes, without prescribing its complete implementation.
What is instanceof operator also called?
Instanceof operator is also called instanceof checks or instanceof keyword.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

