Unlock the Power of Finite Numbers
The Syntax
The isFinite()
function takes a single parameter, testValue
, which is the value to be tested for finiteness. The syntax is straightforward:
isFinite(testValue)
Return Values
The isFinite()
function returns:
- false if the argument is
Infinity
,NaN
(Not a Number), orundefined
- true for all other arguments
Real-World Examples
Let’s put isFinite()
to the test!
In our first example, we’ll check if the value 5463
is finite:
console.log(isFinite(5463)); // true
As expected, the output is true
, since 5463
is a finite number.
In our second example, we’ll see that isFinite()
returns false
for Infinity
and undefined
:
console.log(isFinite(Infinity)); // false
console.log(isFinite(undefined)); // false
In our third example, we’ll see that isFinite()
returns false
for NaN
(Not a Number) and null
:
console.log(isFinite(NaN)); // false
console.log(isFinite(null)); // false
A Key Benefit
One of the most significant advantages of isFinite()
is that it’s a top-level function, meaning it’s not associated with any object or class. This means you can call it from anywhere without creating an instance, making it a convenient and powerful tool in your JavaScript toolkit.
Related Topic: isNaN()
If you’re interested in learning more about working with numbers in JavaScript, be sure to check out the isNaN() function, which checks if a value is Not a Number (NaN).