Underscore.js _.isError() Method

Beginner
5 min read
Updated: Nov 2026
4 examples
Object

Definition

Returns true if object inherits from an Error (official Underscore docs). Thrown strings, numbers, and plain objects return false.

Pass the required arguments shown below. Underscore object helpers usually return a new value — check whether the source object is mutated.

Syntax

Call _.isError. Start with this line.

Underscore
_.isError(object)
CallWhat it does
_.isError(object)Primary signature.
_.isError(...)Call with the arguments your case needs.

Load Underscore with import _ from "underscore" (or the UMD CDN build) so these helpers are available as _.

Library declarations
Underscore
_.isError(object)

Parameters

ParameterDescription
objectRequired. Value to test

Return Value

Return ValueDescription
*true or false

Underscore.js Examples

Example 1 — Official Docs

A caught TypeError passes. A plain string does not.

Underscore
try {
  throw new TypeError("Example");
} catch (o_O) {
  console.log(_.isError(o_O)); // true
}

console.log(_.isError("Example")); // false
Try It Yourself

How It Works

  1. Throw a TypeError. Catch receives a real Error instance.
  2. Check it. _.isError(o_O) → true.
  3. String look-alike. "Example" is not an Error → false.
  4. Takeaway. Prefer throwing Error objects so type checks work.

Example 2 — Numbers, null, and the Constructor

1, null, and Error fail. new Error() passes.

Underscore
console.log(_.isError(1));          // false
console.log(_.isError(null));       // false
console.log(_.isError(Error));      // false
console.log(_.isError(new Error())); // true
Try It Yourself

How It Works

  1. Primitives / null. Not Error instances → fail.
  2. Error function. The constructor is a function, not an instance.
  3. new Error(). Creates an instance → passes.
  4. Rule. Check instances, not the constructor.

Example 3 — Native Error Subclasses

TypeError, RangeError, and SyntaxError all pass.

Underscore
console.log(_.isError(new TypeError("bad type")));     // true
console.log(_.isError(new RangeError("out of range"))); // true
console.log(_.isError(new SyntaxError("bad syntax")));  // true
Try It Yourself

How It Works

  1. Subclasses inherit Error. Their tag still reports as Error.
  2. TypeError / RangeError / SyntaxError. All pass.
  3. Same for others. EvalError, ReferenceError, URIError too.
  4. Takeaway. One check covers the whole Error family.

Example 4 — Thrown Strings vs Error Objects

You can throw any value. Only Error objects pass.

Underscore
try {
  throw "oops";
} catch (err) {
  console.log(_.isError(err)); // false
}

try {
  throw new Error("oops");
} catch (err) {
  console.log(_.isError(err)); // true
}

console.log(_.isError({ name: "Error", message: "oops" })); // false
Try It Yourself

How It Works

  1. Thrown string. Catch gets a string → fails.
  2. Thrown Error. Catch gets an Error → passes.
  3. Look-alike object. Having name/message is not enough.
  4. Best practice. Always throw new Error(…) (or a subclass).

Browser & Runtime Support

_.isError ships with Underscore.js 1.8.0+. It runs anywhere Underscore runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install underscore.

✓ Stable · Underscore 1.8+

_.isError()

Available in [email protected]+ (UMD / ESM). Works in evergreen browsers and current Node LTS when Underscore is loaded.

100% With Underscore 1.8+
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
_.isError Underscore 1.8+

Bottom line: Safe for production once Underscore 1.8+ is on the page or in your bundle. Not a native browser API — load Underscore first. Prefer a pinned CDN version (e.g. [email protected]).

Frequently Asked Questions

_.isError(object) returns true when the value inherits from Error — new Error(), new TypeError(), and other native Error subclasses. Numbers, null, strings, plain objects, and the Error constructor function return false.
The docs throw new TypeError("Example"), catch it, and call _.isError(o_O), which returns true. The catch value is a real Error instance.
Yes. EvalError, RangeError, ReferenceError, SyntaxError, TypeError, and URIError all return true, just like new Error().
No. JavaScript lets you throw any value. A caught string is still a string. Only Error objects pass.
typeof new Error() is "object", so typeof is too broad. instanceof Error usually agrees in the same window. Underscore uses the [object Error] tag, which is more consistent across iframes.
No. It is a stable Underscore helper added in version 1.8.0. Use it before reading name, message, or stack on a caught value.

Next: _.isSymbol()

Test whether a value is a Symbol — another core Underscore type check.

_.isSymbol() 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.

10 people found this page helpful