instanceof

The JavaScript operator that checks whether an object was created by a given class, by walking its prototype chain.

In more detail

err instanceof HttpError narrows err so its status is available, which is the standard way to tell error classes apart in a catch block. It only works with classes, not interfaces or type aliases, which do not exist at run time. Objects from another realm, such as an iframe, fail the check.

Related terms

Taught in

References