A numeric field can contain NaN or infinity even after it has become a number. Number.isFinite checks the value without coercing a string.
Worked example
console.log([4, NaN, Infinity, "4"].map(Number.isFinite));Result
[ true, false, false, false ]Implementation notes
Decide where numeric text becomes a number. Coercing an empty string first can turn missing input into zero before the finiteness check runs.
Try it yourself
Compare 0, "0", NaN and Infinity at the validation boundary.
Open the JavaScript example →Editorial date September 13, 2025 · Published December 6, 2026