JavaScript isFinite() vs. Number.isFinite(): Checking finite numbers
The global isFinite(value) converts its argument to a number before checking it. Number.isFinite(value) only accepts an existing finite Number. Both reject NaN and either infinity, but strings and missing values need care.
What counts as a finite number
isFinite(12.5); // true
isFinite(Infinity); // false
isFinite(-Infinity); // false
isFinite(NaN); // false
A finite Number is neither infinity nor NaN. NaN means Not-a-Number and can result from an invalid calculation or conversion. The string "Not a Number" is different from that numeric value. isFinite() can return true for an argument that was never a Number.
Compare the two functions
| Input | isFinite() |
Number.isFinite() |
|---|---|---|
0 |
true |
true |
-3.5 |
true |
true |
"12" |
true |
false |
"" |
true |
false |
null |
true |
false |
Infinity |
false |
false |
NaN |
false |
false |
Global isFinite() converts an empty string and null to 0. A numeric string can therefore pass. Number.isFinite() returns false for any non-Number value and never coerces it.
Test input before and after conversion
Save the code as finite-number.html and open it. The field supplies a string. The demo trims the text, rejects blanks, and compares the two checks before and after Number().
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Compare isFinite and Number.isFinite</title>
</head>
<body>
<h1>Check finite numbers</h1>
<label for="value">Input to check</label>
<input id="value" value="12.5">
<button id="check" type="button">Check</button>
<button id="restore" type="button">Restore</button>
<pre id="output"></pre>
<script>
const input = document.getElementById("value");
const output = document.getElementById("output");
function check() {
const raw = input.value.trim();
if (raw === "") {
output.textContent = "Enter a value.";
return;
}
const number = Number(raw);
output.textContent = [
`Input type: ${typeof raw}`,
`isFinite(raw): ${isFinite(raw)}`,
`Number.isFinite(raw): ${Number.isFinite(raw)}`,
`Number(raw): ${number}`,
`Number.isFinite(number): ${Number.isFinite(number)}`
].join("\n");
}
document.getElementById("check").addEventListener("click", check);
document.getElementById("restore").addEventListener("click", () => {
input.value = "12.5";
check();
});
check();
</script>
</body>
</html>
For 12.5, the global check on the string is true and the strict check is false. After conversion, the strict check is true. Try abc for NaN, Infinity for a nonfinite number, and a blank to see the input message. Restore puts 12.5 back.
Check integers, sign, and range separately
Number.isFinite(1.5); // true
Number.isInteger(1.5); // false
Number.isFinite(-10); // true
const amount = 12.5;
const positiveFinite = Number.isFinite(amount) && amount > 0;
Finite values can be fractional, negative, or outside an allowed range. Add Number.isInteger() or a sign or bounds test when needed. Large finite integers may be inexact, so use Number.isSafeInteger() when exact integer representation matters. Global isFinite() can throw a TypeError for a Symbol or BigInt. The strict function returns false.
Separate empty optional input from an invalid number
Run the code in the Console with text such as input.value. It returns empty for whitespace and uses Number.isFinite() after converting a nonblank value. A successful result carries the number.
{
function readOptionalNumber(raw) {
const text = raw.trim();
if (text === "") return { status: "empty" };
const value = Number(text);
return Number.isFinite(value)
? { status: "valid", value }
: { status: "invalid" };
}
for (const input of [" ", "0", "1.5e2", "Infinity", "abc"]) {
console.log(JSON.stringify(readOptionalNumber(input)));
}
}
The results are empty, valid with 0, valid with 150, and invalid twice. A required field can treat empty as an error. Number() accepts exponent and hexadecimal notation. Check the original text before converting if only decimal notation is allowed.




