.isFinite()
Published Oct 12, 2021Updated Oct 13, 2021
Contribute to Docs
The .isFinite()
method is a part of the Number
class in JavaScript.
It accepts a single argument, value
, returns true
if the passed argument is a finite number, and returns false
if the passed argument is either positive Infinity
, negative Infinity
, or NaN
.
Syntax
Number.isFinite(value);
value
(required): The value to check.
Examples
To verify if a value is a finite number or not:
const x = 1 / 0;// x = Infinityconsole.log(Number.isFinite(x));// Output: false
const y = 0 / 0;// y = NaNconsole.log(Number.isFinite(y));// Output: false
const z = 10 / 5;// z = 2console.log(Number.isFinite(z));// Output: true
The above example passes an Infinity
, a NaN
, and an integer value, into the Number.isFinite()
method to verify if each value is finite or not. The result is then printed.
Codebyte Example
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.