ECMAScript 2026
⚠️ Baseline Newly AvailableError.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.
💡 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 |
|---|---|---|
value | any | Value to test. Any type accepted. |
| Return | boolean | true for Error instances, false otherwise. |
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
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.
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.
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
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 | ❌ Fails | Same-realm only |
Error.isError | ✅ Works | Any error source |
⚠️ Common Mistakes
- Using duck typing. A plain object with message/name is NOT an Error. Use isError.
- Assuming old browser support. Check Baseline — this is new in 2026.
- Using it for DOMException. DOMException is a separate interface — check separately if needed.
- Forgetting to handle non-error throws. JavaScript allows
throw "string". Always check type first.
❓ 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.