The Number.isfinite() method in JavaScript is used to check whether the passed value is a finite number or not.
The Number.isfinite() method is different from the isfinite() method since this method doesn’t forcibly convert the parameter to a number and it does not return true for any value that is not of the type number. On the other hand, the global isfinite() method converts the tested value to a number first and then tests it
Syntax:
Number.isFinite(value)
Parameters: This method accepts a single parameter value. It is the number that the user wants to check for finiteness.
Return Value: The number.isfinite() method returns a boolean value i.e. either true or false. It returns true if the passed value is of the type Number, and equates to a finite number else it returns false.
Example: Below is an example of the Number.isFinite() Method.
Javascript
console.log(Number.isFinite(111)); |
true
Passing a negative number as an argument: If the negative number passed to the method is finite then the method will return true otherwise false.
Example: In this example, we will pass a negative number as an argument.
Javascript
console.log(Number.isFinite(-2)); |
true
Passing a positive number as an argument: If the positive number passed to the method is finite then the method will return true otherwise false.
Example: In this example, we will pass a positive number as an argument.
Javascript
console.log(Number.isFinite(2)); |
true
Passing zero as an argument: If zero is passed to the method then the method will return true as zero is a finite number.
Example: In this example, we will pass 0 as an argument.
Javascript
console.log(Number.isFinite(0)); |
true
Passing an equation as an argument: If the equation evaluates to a finite number then the method will return true otherwise false.
Example: In this example, we will pass an equation as an argument.
Javascript
console.log(Number.isFinite(7-3+2)); |
true
Passing an equation (resulting in infinite) as an argument: If the equation after evaluating does not give a finite numeric value then the method will return false.
Example: In this example, we will pass an equation that does not give a finite value after evaluation as an argument.
Javascript
console.log(Number.isFinite(0/0)); |
false
Passing a word as an argument: Since a word is not of type integer, so the Number.isFinite() will not convert it to a number and will return false.
Example: In this example, we will pass a string as an argument.
Javascript
console.log(Number.isFinite( "strong" )); |
false
Passing number(string) as an argument: Since a string is not of type integer, so the Number.isFinite() will not convert it to a number and will return false.
Example: In this example, we will pass a number as a string as an argument.
Javascript
console.log(Number.isFinite( "5" )); |
false
We have a complete list of Javascript Number Methods, to check those please go through the Javascript Number Complete Reference article.
Supported Browsers:
- Google Chrome 19
- Internet Explorer 12
- Firefox 16
- Apple Safari 09
- Opera 15 and above