Underscore.js _.isNaN() Method

Beginner
5 min read
Updated: Nov 2026
4 examples
Object

Definition

Returns true if object is NaN (official Underscore docs). Unlike native isNaN, it does not treat other “not-number” values as NaN.

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

Syntax

Call _.isNaN. Start with this line.

Underscore
_.isNaN(object)
CallWhat it does
_.isNaN(object)Primary signature.
_.isNaN(...)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
_.isNaN(object)

Parameters

ParameterDescription
objectRequired. Value to test

Return Value

Return ValueDescription
*true or false

Underscore.js Examples

Example 1 — Official Docs

NaN passes. undefined does not.

Underscore
_.isNaN(NaN);
// → true

_.isNaN(undefined);
// → false
Try It Yourself

How It Works

  1. NaN. Real Number NaN → true.
  2. undefined. Not a Number → false.
  3. Native contrast. isNaN(undefined) would be true.
  4. Takeaway. Underscore avoids coercion surprises.

Example 2 — Common Look-alikes

null, strings, and numbers fail. NaN passes.

Underscore
console.log(_.isNaN(null));   // false
console.log(_.isNaN(""));     // false
console.log(_.isNaN(42));     // false
console.log(_.isNaN(NaN));    // true
Try It Yourself

How It Works

  1. null / "". Not Number NaN → fail.
  2. 42. Ordinary number → fail.
  3. NaN. The only pass in this set.
  4. Rule. Only the Number NaN passes.

Example 3 — vs _.isNumber

NaN passes both. Infinity passes isNumber only.

Underscore
console.log(_.isNaN(NaN), _.isNumber(NaN));           // true true
console.log(_.isNaN(Infinity), _.isNumber(Infinity)); // false true
console.log(_.isNaN(42), _.isNumber(42));             // false true
Try It Yourself

How It Works

  1. NaN. Number type and NaN → both pass.
  2. Infinity. Number, but not NaN → only isNumber.
  3. 42. Finite Number → only isNumber.
  4. Pick the tool. Type check vs NaN check.

Example 4 — Computed NaN

0/0 and failed parsing quietly produce NaN.

Underscore
console.log(_.isNaN(0 / 0));                  // true
console.log(_.isNaN(parseFloat("nope")));     // true
console.log(_.isNaN(Number("not a number"))); // true
Try It Yourself

How It Works

  1. 0 / 0. Classic NaN-producing math.
  2. parseFloat. Bad input → NaN.
  3. Number(...). Same idea via constructor.
  4. Use case. Guard results before more arithmetic.

Browser & Runtime Support

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

✓ Stable · Underscore 0.4.7+

_.isNaN()

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

100% With Underscore 1.x
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
_.isNaN Underscore 0.4.7+

Bottom line: Safe for production once Underscore 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

_.isNaN(object) returns true only when the value is the Number NaN — for example NaN or 0/0. undefined, null, strings, Infinity, and ordinary numbers return false.
_.isNaN(NaN) returns true. _.isNaN(undefined) returns false. Native isNaN(undefined) returns true. That pair shows Underscore only accepts real NaN values.
Native isNaN coerces its argument. isNaN(undefined) is true because undefined becomes NaN. Underscore requires a Number that is NaN, so undefined, null, and strings fail.
isNumber is a type check and includes NaN, Infinity, and finite numbers. isNaN is the narrow case: only NaN passes. Infinity and 42 pass isNumber and fail isNaN.
Number.isNaN (ES2015) is also strict and does not coerce. _.isNaN and Number.isNaN usually agree on NaN vs undefined. Prefer Number.isNaN when you do not need Underscore.
No. It is a stable Underscore helper (since 0.4.7). Use it when you need to detect the actual Number NaN without native coercion surprises.

Next: _.isNull()

Detect null values — another core Underscore type check.

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