Dev Helpers

JavaScript / Numbers

Validate finite numbers

Dev Helpers · September 13, 2025

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

Related articles

Sum distances with a Euclidean norm

A diagonal is longer than either of its components. Math.hypot combines perpendicular distances without making the caller square each input.

Build an OS-independent path

Path conventions belong to the destination. Use an explicit path flavour when generating portable asset names.

Resolve ranked ties

A leaderboard needs an explicit tie policy. Ranking tied scores and sorting their display order are separate decisions.