The instanceof Operator

Learn how to use the instanceof operator in TypeScript to test object inheritance and determine class instances.

Introduction to the instanceof operator

JavaScript provides the instanceof operator to test whether the given function name appears in the prototype of an object.

In TypeScript terms, the use of this keyword allows us to detect whether an object is an instance of a class or whether it has been derived from a particular class.

This is best illustrated with an example as follows:

Get hands-on with 1400+ tech skills courses.