Master Code
On The Go

Learn. Practice. Build.

Home › Code Snippets › JavaScript › Reference › Error.isError()

ECMAScript 2026

⚠️ Baseline Newly Available

Error.isError()

Reliably detect Error objects across realms. Replaces broken instanceof checks.

Last updated: October 2026

Definition: Error.isError(value) returns true if the value is an Error object, false otherwise. Unlike instanceof Error, it works reliably across iframes, workers, and realms [citation:1][citation:20].

🎬 Live Example

Five common isError patterns. Click any button to see the output.

Input:

                
Output:

            

💡 isError works where instanceof fails — cross-realm, cross-iframe.

📝

Basic Syntax

Error.isError(value)

// Returns: boolean
// Works across realms (iframes, workers, vm)
// Works on subclasses (TypeError, RangeError, etc.)
// Does NOT trust duck-typing (plain objects return false)

🎯 Parameters & Return

Parameter Type Description
valueanyValue to test. Any type accepted.
Returnbooleantrue for Error instances, false otherwise.
1

Basic Error Detection

Error.isError(new Error("x"));      // true
Error.isError(new TypeError("x"));  // true
Error.isError("x");                 // false
Error.isError({});                  // false
Error.isError(null);                // false
2

The Cross-Realm Bug instanceof Can't Fix

// In the main window:
const iframe = document.createElement("iframe");
document.body.appendChild(iframe);

const ForeignError = iframe.contentWindow.Error;
const foreign = new ForeignError("oops");

foreign instanceof Error;   // false ❌
Error.isError(foreign);     // true  ✅

Why: Each realm has its own Error constructor. instanceof compares constructor identity, which differs across realms.

3

Duck Typing Rejected

// Not an Error — just looks like one
const fake = { message: "oops", name: "Error" };

Error.isError(fake);      // false
fake instanceof Error;    // false
// Both are correct here

Note: isError does NOT do duck typing. It checks the internal error marker.

4

Works on Subclasses

Error.isError(new TypeError());     // true
Error.isError(new RangeError());    // true
Error.isError(new SyntaxError());   // true
Error.isError(new ReferenceError()); // true

class MyError extends Error {}
Error.isError(new MyError());       // true
5

Real-World: Safe Error Handler

function handleError(e) {
  if (Error.isError(e)) {
    log(e.message, e.stack);
  } else {
    // Maybe a string, object, or DOM exception
    log("Unknown error:", e);
  }
}

// Works regardless of where the error came from

🎯 Error.isError vs instanceof Error

Check Cross-Realm Use when
instanceof Error❌ FailsSame-realm only
Error.isError✅ WorksAny error source

⚠️ Common Mistakes

❓ Frequently Asked Questions

What does Error.isError() do in JavaScript?

Error.isError(value) returns true if the value is an Error object, false otherwise. It works reliably across iframes, workers, and realms where instanceof Error fails.

What is the difference between Error.isError() and instanceof Error?

instanceof Error fails when the error comes from a different realm (iframe, worker, vm context) because each realm has its own Error constructor. Error.isError() checks the internal error marker and works reliably everywhere.

Does Error.isError() work on subclasses?

Yes. Error.isError() returns true for TypeError, RangeError, SyntaxError, and any custom subclass that extends Error.

When was Error.isError() added to JavaScript?

Error.isError() was approved as part of ECMAScript 2026 (June 2026). It reached Baseline Newly Available in 2026.

Does Error.isError() work on plain objects with message and name?

No. A plain object like { message: 'oops', name: 'Error' } is not an Error instance. Error.isError() returns false.

🎯 What's Next?

← All JavaScript Reference