Underscore.js _.isNumber() Method

Beginner
5 min read
Updated: Nov 2026
4 examples
Object

Definition

Returns true if object is a Number (including NaN) (official Underscore docs). Numeric strings such as "8" 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 _.isNumber. Start with this line.

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

Parameters

ParameterDescription
objectRequired. Value to test

Return Value

Return ValueDescription
*true or false

Underscore.js Examples

Example 1 — Official Docs

A computed number passes. A numeric string does not.

Underscore
_.isNumber(8.4 * 5);
// → true

_.isNumber("8");
// → false
Try It Yourself

How It Works

  1. 8.4 * 5. Equals 42 — a Number → true.
  2. "8". String type → false.
  3. Job of the helper. Number type, not “looks numeric.”
  4. Takeaway. Coerce strings yourself if you need that.

Example 2 — Common Numbers

Zero, negatives, and decimals all pass.

Underscore
console.log(_.isNumber(0));     // true
console.log(_.isNumber(-3));    // true
console.log(_.isNumber(3.14));  // true
Try It Yourself

How It Works

  1. Zero. Still a Number → passes.
  2. Negative. Sign does not change the type.
  3. Float. Decimals are Numbers too.
  4. Rule. Everyday numeric literals all pass.

Example 3 — vs typeof

typeof misses boxed Number objects. isNumber does not.

Underscore
console.log(_.isNumber(8), typeof 8);
// → true "number"

console.log(_.isNumber(new Number(8)), typeof new Number(8));
// → true "object"
Try It Yourself

How It Works

  1. Primitive 8. Both agree — Number.
  2. new Number(8). typeof says object; Underscore still true.
  3. Why. Tag check [object Number] covers both forms.
  4. Takeaway. Prefer _.isNumber when boxed values may appear.

Example 4 — NaN and Infinity

NaN and Infinity pass isNumber. isFinite rejects both.

Underscore
console.log(_.isNumber(NaN), _.isFinite(NaN), _.isNaN(NaN));
// → true false true

console.log(_.isNumber(Infinity), _.isFinite(Infinity));
// → true false
Try It Yourself

How It Works

  1. NaN. Number type → isNumber true; use isNaN to name it.
  2. isFinite. Rejects NaN and Infinity.
  3. Infinity. Still a Number type.
  4. Pick the tool. Type vs usable finite value.

Browser & Runtime Support

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

✓ Stable · Underscore 1.x

_.isNumber()

Available in [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
_.isNumber Underscore 1.x+

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

_.isNumber(object) returns true when the value is a Number — integers, floats, 0, Infinity, NaN, and boxed new Number() objects. Strings such as "8", arrays, objects, and null return false.
_.isNumber(8.4 * 5) returns true. That product is 42, a real Number, so Underscore treats it as a Number.
Yes. The Underscore docs say including NaN. In JavaScript, NaN is a Number (typeof NaN === "number"). Use _.isNaN when you specifically need to detect NaN, or _.isFinite when you need a usable finite number.
typeof 8 === "number" agrees for primitives, including NaN and Infinity. typeof new Number(8) is "object", so typeof misses boxed numbers. Underscore uses a [object Number] tag test, so both forms pass isNumber.
isNumber is the type check: NaN and Infinity pass. isFinite asks whether the value is a finite Number, so NaN and Infinity fail. Use isFinite before arithmetic that must stay in range.
No. It is a stable Underscore 1.x helper used to decide whether a value is a Number before you do math or compare numeric options.

Next: _.isNaN()

Detect Number NaN safely — the natural follow-up to isNumber.

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