Lodash _.isFinite() method

Beginner
⏱️ 6 min read
📚 Updated: May 2026
🎯 3 Code examples
🚀 3 Try-it labs
Lodash

What you’ll learn

  • How _.isFinite(value) restricts inputs to primitive numbers.
  • Why Infinity, -Infinity, and NaN fail the check.
  • How lodash differs from legacy global isFinite coercion.
  • Why boxed numbers and numeric strings do not pass.

Prerequisites

Comfort with JavaScript number literals and the difference between primitives and objects.

  • You know Infinity and NaN are special IEEE-754 values.
  • Try-it labs load lodash from the CDN.

Overview

Reach for _.isFinite after parsing unknown inputs—guarding sliders, pagination math, canvas transforms, or analytics counters—without accidentally accepting coerced strings.

Primitive-only

typeof gate keeps strings and objects out.

No coercion

Unlike global isFinite, lodash will not cast numeric text.

Reject extremes

Infinity and NaN fail native finite checks.

Syntax

javascript
_.isFinite(value)
  • value: any value to test.
  • Returns: true if value is a finite primitive number; otherwise false.
1

Ordinary finite numbers

Integers and fractional literals both qualify when they stay within finite IEEE bounds.

javascript
import isFinite from "lodash/isFinite";

console.log(
  "finiteInt: " + isFinite(42) + "\n" +        // true
  "finiteFloat: " + isFinite(-12.875)           // true
);
Try it Yourself
2

Infinity, NaN, and numeric strings

Non-finite math values fail; string digits fail because lodash refuses coercion.

javascript
import isFinite from "lodash/isFinite";

console.log(
  "posInfinity: " + isFinite(Infinity) + "\n" +   // false
  "nanVal: " + isFinite(NaN) + "\n" +           // false
  "numericStr: " + isFinite("99")              // false
);
Try it Yourself
3

Primitive versus boxed number

Coerce explicitly with Number(...) if APIs might hand back object wrappers.

javascript
import isFinite from "lodash/isFinite";

console.log(
  "primitiveNum: " + isFinite(7) + "\n" +       // true
  "boxedNum: " + isFinite(Object(7))           // false
);
Try it Yourself

📋 _.isFinite vs related checks

APIMatches
_.isFinite(x)Finite primitive numbers only.
Number.isFinite(x)Nearly identical semantics for finite primitive numbers.
isFinite(x) (global)Coerces operands—strings may become finite numbers unexpectedly.
_.isNumber(x)Broader—still true for NaN/Infinity; pair with _.isFinite when needed.

Pitfalls to avoid

Forms

Query strings arrive as text

Parse with Number/parseFloat first—lodash will not treat "42" as numeric.

JSON

Numbers survive; strings do not

Serialized payloads often mix strings—normalize schema fields before validation.

BigInt

BigInt is not typeof number

typeof 1n === "bigint", so _.isFinite returns false—handle BigInt separately.

❓ FAQ

Global isFinite coerces values (for example strings). Lodash requires an actual primitive number first, so _.isFinite("3") is false while isFinite("3") can be true.
They agree for everyday inputs: both reject non-number types without coercion and reject Infinity and NaN.
Boxed numbers have typeof "object". Lodash only accepts typeof "number" primitives.
Negative zero is still a finite number in IEEE math, so lodash reports true—same as Number.isFinite(-0).

Summary

  • Purpose: validate finite primitive numbers without accidental coercion.
  • Reject: strings, boxed numbers, Infinity, and NaN.
  • Next: explore more on Lodash _.isFunction().
Did you know?

_.isFinite returns true only when typeof value === "number" and the built-in isFinite test passes—so numeric strings, boxed numbers, null, and booleans are all false, unlike global isFinite("3").

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.

6 people found this page helpful