Number.isFinite()
The single best "is this a usable number" check. It excludes the three values that break arithmetic — NaN and both infinities — and unlike the global version it does not convert its argument first.
Demo
The pair is [Number.isFinite(v), isFinite(v)]. For genuine numbers the two agree, and for non-numeric text both are false. The divergence appears with a numeric STRING: the global converts '5' to 5 and answers true, while the static answers false because a string is not a number. The auto input here turns numeric-looking text into a real number first, so see the examples below for the raw-string contrast. Neither form can be shown Infinity through a text box.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| value | any | yes | Any value. Non-numbers are false without conversion, as are NaN, Infinity and -Infinity. |
Return value
boolean — True only for a number that is neither infinite nor NaN. No coercion — a numeric string is false.
Common patterns
const n = Number(input); if (!Number.isFinite(n)) reject();
if (!Number.isFinite(result)) throw new Error("overflow");
const avg = count ? total / count : 0;
Examples
Pitfalls
isFinite('')
Number.isFinite('')
10 / 0
denominator === 0 ? 0 : 10 / denominator
Number.isFinite('42')
const s = '42'; s.trim() !== '' && Number.isFinite(Number(s))
Number.isFinite(Infinity - 1000)
if (!Number.isFinite(x)) handle();
When to use
- Validating that a converted value is usable in arithmetic
- Detecting overflow or division by zero
- Guarding values before they reach a chart, a layout calculation or a database
- Any check where NaN and Infinity should both fail
- The value is a string → convert with Number first
- You only care about NaN → Number.isNaN
- You need a whole number → Number.isInteger
- The global isFinite → it coerces, and rarely helps
Notes
FAQ
Because it converts its argument first, so it answers true for numeric strings, for the empty string and for null. That makes it a loose "could this be a number" test rather than a check on the value you actually hold.
isFinite(''); // true — '' converts to 0 Number.isFinite(''); // false