JavaScript Error isError() Method

Beginner
6 min read
Updated: Nov 2026
3 examples
Static method

Definition

Error.isError(value) checks whether a value is a real Error object. It returns true for Error, for built-in types such as TypeError and RangeError, and for classes that extend Error. For every other value it returns false.

It is more reliable than value instanceof Error. That check can say true for an object that only inherits from Error.prototype, and false for a real error that was created in another iframe or window. Error.isError() looks at how the object was made, so it answers correctly in both cases. It is a newer method, so see the browser support section.

Remember
Error.isError(new Error("x"))       → true
Error.isError(new TypeError("x"))   → true
Error.isError({ message: "x" })     → false
Error.isError("x")                  → false
Error.isError()                     → false

It never throws and never changes the value.

Syntax

Call isError() on the Error constructor itself, not on the value you want to test. Pass that value as the only argument.

JavaScript
Error.isError(value);
CallWhat it does
Error.isError(err)Returns true for a real error object and false for anything else.
if (Error.isError(problem)) { ... }Use it in a catch block to treat errors and other thrown values differently.
typeof Error.isError === "function"Check that the method exists first when your code may run in an older browser or Node.js version.

Built into JavaScript as a newer method; no import required, but check that it exists in older environments. Siblings: Error.captureStackTrace() and toString().

Library declarations
JavaScript
// Error.isError (newer JavaScript API)
Error.isError(value)

// returns boolean

Parameters

ParameterDescription
valueThe value to test. It can be anything: an error, a plain object, a string, a number, null or undefined. Nothing you pass can make the method throw.

Return Value

Return ValueDescription
trueThe value is an Error object: it was created by Error, by a built-in type such as TypeError, or by a class that extends one of them.
falseAnything else, including strings like "Error: Oops", plain objects with a message, null, undefined and objects that only copy Error.prototype.

JavaScript Examples

Example 1 — Test Different Kinds of Values

Pass real errors and look-alikes to Error.isError() and print each answer.

JavaScript
const samples = [
  ["new Error('Oops')", new Error("Oops")],
  ["new TypeError('Bad type')", new TypeError("Bad type")],
  ["{ name: 'Error', message: 'Oops' }", { name: "Error", message: "Oops" }],
  ["'Error: Oops'", "Error: Oops"],
  ["null", null]
];

for (const [label, value] of samples) {
  console.log(label + " -> " + Error.isError(value));
}
Try It Yourself

How It Works

  1. A list of samples. Each item holds a label for the output and the value to test, so the loop prints what was tested next to the answer.
  2. Real errors say true. new Error() and new TypeError() both create genuine Error objects.
  3. Look-alikes say false. An object with name and message, a string that looks like an error message, and null are not Error objects, however similar they look.

Example 2 — Compare isError() with instanceof

An object that only inherits from Error.prototype fools instanceof but not Error.isError().

JavaScript
class DiskError extends Error {}

const real = new DiskError("Disk full");
const fake = Object.create(Error.prototype);

console.log("real instanceof Error: " + (real instanceof Error));
console.log("real isError: " + Error.isError(real));
console.log("fake instanceof Error: " + (fake instanceof Error));
console.log("fake isError: " + Error.isError(fake));
Try It Yourself

How It Works

  1. Two objects. real is created with new DiskError(), so it is a genuine error. fake is a plain object whose prototype is Error.prototype.
  2. instanceof follows the prototype. It only asks whether Error.prototype is somewhere in the chain, so it says true for both objects.
  3. isError() checks how it was made. Only real was built by the Error machinery, so only real gets true. The same idea makes it work for errors from other iframes.

Example 3 — Handle Anything a catch Block Receives

JavaScript lets you throw any value. Check what you caught before you read message, and keep a fallback for older engines.

JavaScript
function isError(value) {
  return typeof Error.isError === "function"
    ? Error.isError(value)
    : value instanceof Error;
}

const jobs = [
  () => { throw new Error("Disk full"); },
  () => { throw "timeout"; },
  () => { throw { code: 500 }; },
  () => { throw new RangeError("Quota exceeded"); }
];

for (const job of jobs) {
  try {
    job();
  } catch (problem) {
    if (isError(problem)) {
      console.log("Error: " + problem.message);
    } else {
      console.log("Not an Error: " + JSON.stringify(problem));
    }
  }
}
Try It Yourself

How It Works

  1. A safe wrapper. isError() uses Error.isError() when it exists and falls back to instanceof Error when it does not, so the code runs in older environments too.
  2. Four different throws. Two jobs throw real errors, one throws a string and one throws a plain object. All of them land in the same catch block.
  3. Handle each kind. Real errors have a message to print. Other values have none, so JSON.stringify() shows what they actually are.

Browser & Runtime Support

Error.isError() is a newer JavaScript method. Current versions of the major browsers and Node.js 24 have it; older ones do not.

✓ Newer API · check support

Error.isError()

Supported in Chrome 134+, Edge 134+, Firefox 138+ and Node.js 24+. Other browsers and runtimes follow in recent versions, so check the version. Internet Explorer never got it.

Newer Check before use
Google Chrome 134+ · Desktop & Mobile
Full support
Microsoft Edge 134+ · Chromium
Full support
Mozilla Firefox 138+ · Desktop & Mobile
Full support
Apple Safari Check the version · macOS & iOS
Check support
Opera Recent versions · Chromium based
Check support
Samsung Internet Recent versions · Android
Check support
Android WebView Recent versions · Chromium based
Check support
Node.js 24+ · Server runtime
Supported
Deno Recent versions · JavaScript runtime
Supported
Bun Check the version · JavaScript runtime
Check support
Internet Explorer No native support
Not supported
Error.isError() Growing

Bottom line: Fine for current browsers and Node.js 24, but keep the instanceof Error fallback from Example 3 when you must support older ones.

Frequently Asked Questions

It returns true when the value is a real Error object (an Error, a built-in type such as TypeError, or an instance of a class that extends Error) and false for everything else, including strings, plain objects, null and undefined.
instanceof only checks the prototype chain, so an object created with Object.create(Error.prototype) passes, and a real error from another iframe or window fails. Error.isError() checks how the object was created, so it gets both cases right.
Yes. A class that extends Error (or TypeError and so on) creates real error objects, so Error.isError() returns true for its instances. A class that does not extend Error returns false, even if it has name and message properties.
Fall back to instanceof Error: typeof Error.isError === "function" ? Error.isError(value) : value instanceof Error. The fallback is slightly less strict, but it works everywhere and is usually good enough for catch blocks.
JavaScript lets you throw any value, so code can write throw "timeout" or throw { code: 500 }. Libraries and callbacks sometimes do this too. Check the value with Error.isError() before you read err.message, because a string or a number has no message.

Next: toString()

Learn how an error becomes the text "name: message" and how you can change it.

toString() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

14 people found this page helpful