Error.isError()

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

The Error.isError() static method determines whether the passed value is an Error.

Syntax

js
Error.isError(value)

Parameters

value

The value to be checked.

Return value

true if value is an Error; otherwise, false.

Description

Error.isError() checks if the passed value is an Error. It does so by performing a branded check for a private field initialized by the Error() constructor. This is the same mechanism used by Array.isArray(), which is in turn similar to the mechanism used by the in operator.

It is a more robust alternative to instanceof Error because it avoids false positives and false negatives:

  • Error.isError() rejects values that aren't actual Error instances, even if they have Error.prototype in their prototype chain — instanceof Error would accept these as it does check the prototype chain.
  • Error.isError() accepts Error objects constructed in another realm — instanceof Error returns false for these because the identity of the Error constructor is different across realms.

Error.isError() returns true for DOMException instances. This is because, although DOMException is not specified as a real subclass of Error (the Error constructor is not the prototype of the DOMException constructor), DOMException still behaves like Error for all branded checking purposes.

Examples

Using Error.isError()

js
// all following calls return true
Error.isError(new Error());
Error.isError(new TypeError());
Error.isError(new DOMException());
try {
  1 + 1n;
} catch (e) {
  console.log(Error.isError(e)); // The operation threw a TypeError, so this returns true
}

// all following calls return false
Error.isError();
Error.isError({});
Error.isError(null);
Error.isError(undefined);
Error.isError(17);
Error.isError("Error");
Error.isError(true);
Error.isError(false);
// This is not an error, because the object does not have the private field
// initialized by the Error constructor
Error.isError({ __proto__: Error.prototype });

instanceof vs. Error.isError()

When checking for Error instance, Error.isError() is preferred over instanceof because it works across realms.

js
const iframe = document.createElement("iframe");
document.body.appendChild(iframe);
const xError = window.frames[window.frames.length - 1].Error;
const error = new xError();

// Correctly checking for Error
Error.isError(error); // true
// The prototype of error is xError.prototype, which is a
// different object from Error.prototype
error instanceof Error; // false

Normalizing caught errors

You can use Error.isError() to detect if the caught value is an error and normalize it to an error object.

js
try {
  throw "Oops; this is not an Error object";
} catch (e) {
  if (!Error.isError(e)) {
    e = new Error(e);
  }
  console.error(e.message);
}

Specifications

Specification
ECMAScript® 2027 Language Specification
# sec-error.iserror

Browser compatibility

desktop mobile server
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Bun
Deno
Node.js
isError
Chrome – Full support
Chrome 134 (Release date: 2025-03-04)
footnote Full support
Edge – Full support
Edge 134 (Release date: 2025-03-06)
footnote Full support
Firefox – Full support
Firefox 138 (Release date: 2025-04-29)
footnote Full support
Opera – Full support
Opera 119 (Release date: 2025-05-13)
footnote Full support
Safari – Partial support
Safari 18.4 (Release date: 2025-03-31)
footnote Partial support
footnote Returns false for DOMException instances.
Chrome Android – Full support
Chrome Android 134 (Release date: 2025-03-04)
footnote Full support
Firefox for Android – Full support
Firefox for Android 138 (Release date: 2025-04-29)
footnote Full support
Opera Android – Full support
Opera Android 88 (Release date: 2025-03-19)
footnote Full support
Safari on iOS – Partial support
Safari on iOS 18.4 (Release date: 2025-03-31)
footnote Partial support
footnote Returns false for DOMException instances.
Samsung Internet – Full support
Samsung Internet 29 (Release date: 2025-10-25)
footnote Full support
WebView Android – Full support
WebView Android 134 (Release date: 2025-03-04)
footnote Full support
WebView on iOS – Partial support
WebView on iOS 18.4 (Release date: 2025-03-31)
footnote Partial support
footnote Returns false for DOMException instances.
Bun – Full support
Bun 1.1.39 (Release date: 2024-12-17)
footnote Full support
Deno – Full support
Deno 2.2 (Release date: 2025-02-19)
footnote Full support
Node.js – Partial support
Node.js 24 – 24.2 (Release date: 2025-05-06)
footnote Partial support
footnote Returns false for DOMException instances. See issue 56497.
Node.js – Full support
Node.js 24.3 (Release date: 2025-06-24)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
Has more compatibility info.

See also