JavaScript isFinite()

The JavaScript isFinite() function checks if the passed value is a finite number.

The syntax of the isFinite() function is:

isFinite(testValue)

isFinite() Parameters

The isFinite() function takes in:

  • testValue - The value to be tested for finiteness.

Return value from isFinite()

  • Returns false if the argument is positive or negative Infinity or NaN or undefined.
  • Returns true for other arguments.

Note: isFinite() is a top-level function and is not associated with any object.


Example: Using isFinite()

console.log(isFinite(643511)); // true
console.log(isFinite(null)); // true
// inplicit conversion to number
console.log(isFinite('0')); // true

console.log(isFinite(NaN)); // false
console.log(isFinite(Infinity)); // false
console.log(isFinite(undefined)); // false
console.log(isFinite(-Infinity)); // false

Output

true
true
true
false
false
false
false

Recommended Reading: Javascript isNaN()

Did you find this article helpful?