Strict numeric validation
Validate numeric input before arithmetic or calculations.
JavaScript · Function
Number.isFinite() checks whether a value is a finite JavaScript number. It returns false for non-numbers, NaN, and positive or negative infinity.
Call Number.isFinite(value) to test whether value is both a number and finite. Unlike the global isFinite() function, it does not convert non-number inputs before testing, so non-numbers return false.
Number.isFinite(value)| Name | Type | Description |
|---|---|---|
value | any | The value to be tested for finiteness. |
A Boolean: true for a finite number and false otherwise.
Number, called as Number.isFinite(value) rather than as a method on an individual number.NaN and either sign of infinity fail.value.true reserved for finite numbers.isFinite() when you need strict numeric validation: that function coerces its argument first.null are rejected rather than converted.const values = [42, "42", Infinity, NaN, null];
const finiteNumbers = values.filter(Number.isFinite);
console.log(finiteNumbers); // [42]Only the numeric value 42 passes; strings and other non-finite or non-number values return false.
Validate numeric input before arithmetic or calculations.
Keep only finite numeric elements when processing mixed data.
Reject sentinel values such as NaN and infinities in computation pipelines.
Number.isFinite() test?Number.isFinite(value) returns true only when value has the number type and is not NaN, positive Infinity, or negative Infinity. It returns false for every other value.
Follow-up: How does it differ from global isFinite()? The global function converts non-number arguments first, while Number.isFinite() does not.
The method accepts one value to test and returns a Boolean. Finite numeric values such as 0 and 2e64 produce true; NaN and either infinity produce false.
Follow-up: What happens for a string such as "0"? Number.isFinite("0") is false because the argument is not a number.
Number.isFinite() preferable to global isFinite()?Use it when input must already be a JavaScript number and must also be usable as a finite numeric value. It combines type strictness with rejection of NaN and both infinities.
Follow-up: Would it validate an integer? No; finite fractional values also pass, so use an integer-specific check when integerness is required.
Number.isInteger()Number.isNaN()Number.isSafeInteger()isFinite()