The JavaScript Number.isFinite() method
The Number.isFinite() method returns true only if a value is a finite number — not Infinity, -Infinity or NaN, and not a non-number. Number.isFinite(42) is true; Number.isFinite("42") is false (no coercion). It's safer than the global isFinite().
Overview
Number.isFinite() confirms a value is a real, usable, finite number. It rules out the three problem values that arithmetic can produce — Infinity, -Infinity and NaN — and, crucially, it does not coerce, so anything that isn't already a number (like a string) returns false.
That no-coercion behavior is the difference from the older global isFinite(), which converts its argument first: isFinite("42") is true because the string converts to a number, which is often not what you want. Number.isFinite("42") is false — it only accepts actual numbers. Use the Number. version for reliable validation.
It's the natural guard after arithmetic that might overflow or divide by zero (1 / 0 is Infinity) or fail (parseInt("x") is NaN). It sits with the other strict numeric checks — Number.isNaN() and Number.isInteger() — that all avoid coercion. Use isFinite when "is this a normal number I can safely use" is the question.
Syntax
Number.isFinite(value)
Number.isFinite(42) // true
Number.isFinite(Infinity) // false
Number.isFinite(NaN) // false
Number.isFinite("42") // false (no coercion)
isFinite("42") // true (global, coerces - avoid)
Parameters
The Number.isFinite() method accepts the following parameters.
| Parameter | Description |
|---|---|
value |
The value to test. Returns true only if it is a finite number. |
Example
<pre id="out" style="font:15px ui-monospace,monospace"></pre>
<script>
const values = [42, 1 / 0, NaN, '42', -3.14];
const lines = values.map(v =>
JSON.stringify(v) + ' -> ' + Number.isFinite(v)
);
document.getElementById('out').textContent = lines.join('\n');
</script>
Best practices
- Use
Number.isFinite()(not the globalisFinite()) to avoid coercion. - Guard results of division and parsing, which can produce
InfinityorNaN. - Pair it with Number.isNaN() and Number.isInteger() for thorough numeric checks.
- Convert strings to numbers first if you need to accept numeric strings.
Frequently asked questions
What does Number.isFinite() check?
false for Infinity, -Infinity, NaN and non-numbers.What is the difference between Number.isFinite() and the global isFinite()?
isFinite() coerces its argument first, so isFinite("42") is true. Number.isFinite() doesn't coerce and only accepts real numbers.How do I check for Infinity?
!Number.isFinite(x) && !Number.isNaN(x), or compare directly with Infinity/-Infinity.When would a value be Infinity?
1 / 0) or numbers that overflow the range JavaScript can represent.