Number.isFinite()
The Number.isFinite()
static method determines whether the passed value is a finite number — that is, it checks that a given value is a number, and the number is neither positive Infinity
, negative Infinity
, nor NaN
.
Try it
Syntax
js
Number.isFinite(value)
Parameters
value
-
The value to be tested for finiteness.
Return value
The boolean value true
if the given value is a finite number. Otherwise false
.
Examples
Using isFinite()
js
Number.isFinite(Infinity); // false
Number.isFinite(NaN); // false
Number.isFinite(-Infinity); // false
Number.isFinite(0); // true
Number.isFinite(2e64); // true
Difference between Number.isFinite() and global isFinite()
In comparison to the global isFinite()
function, this method doesn't first convert the parameter to a number. This means only values of the type number and are finite return true
, and non-numbers always return false
.
js
isFinite("0"); // true; coerced to number 0
Number.isFinite("0"); // false
isFinite(null); // true; coerced to number 0
Number.isFinite(null); // false
Specifications
Specification |
---|
ECMAScript Language Specification # sec-number.isfinite |
Browser compatibility
BCD tables only load in the browser
See also
- Polyfill of
Number.isFinite
incore-js
- The
Number
object it belongs to - The global function
isFinite