The Number.isFinite method is used to check if the number passed to the function is a finite number or not.
The argument is considered a
finitenumber if the argument is not equal toPositive InfinityandNegative InfinityandNaN.
Number.isFinite(val)
The argument
valmust be a type ofNumber. Otherwise,falsewill be returned.
The Number.isFinite method returns true if the number passed is a finite number; otherwise, it returns false.
console.log("0 :", Number.isFinite(0)); // trueconsole.log("\n10.12 :", Number.isFinite(10.12)); // trueconsole.log("\n-10 : ", Number.isFinite(-10)); // trueconsole.log("\nInfinity :", Number.isFinite(Infinity)); // falseconsole.log("\n-Infinity :", Number.isFinite(-Infinity)); // falseconsole.log("\nNaN :", Number.isFinite(NaN)); // falseconsole.log("\n'0' :", Number.isFinite('0')); // false, because '0' is a string not a numberconsole.log("\nnull : ", Number.isFinite(null)); // false, because 'null' is not a number
We use the Number.isFinite() method to check if the numbers are finite.
For the numbers 0, 10.12, -10, the isFinite method returns true. This is because they are all finite numbers.
For the numbers +Infinity, -Infinity, NaN, the isFinite method returns false. This is because they are all infinite numbers.
For the '0' string, the isFinite method returns false. This is because '0' is not a Number type.
For null, the isFinite method returns false. This is because null is not a Number type.