This JavaScript tutorial explains how to use the Number method referred to as isInteger() with syntax and examples.
Description
In JavaScript, isInteger() is a Number method that is used to return a Boolean value indicating whether a cost is an integer. Because isInteger() is a technique of the Number object, it ought to be invoked thru the object referred to as Number.
Syntax
In JavaScript, the syntax for the isInteger() approach is:
Number.isInteger(value);
Parameters or Arguments
value
The value to test whether it is an integer.
Returns
The isInteger() method returns true if the value is an integer. Otherwise, it returns false.
If the isInteger() approach is passed a non-numeric value, it will return false. This is due to the fact the isInteger() approach does NOT convert the fee to a number earlier than testing whether or not it is an integer.
Note
The isInteger() method does NOT convert the cost parameter to a numeric cost earlier than deciding whether the price is an integer.
Example
Let’s take a seem at an instance of how to use the isInteger() technique in JavaScript.
For example:
console.log(Number.isInteger(25));
console.log(Number.isInteger(6.7));
console.log(Number.isInteger('25'));
In this example, we have invoked the isInteger() approach the use of the Number class.
We have written the output of the isInteger() technique to the net browser console log, for demonstration purposes, to exhibit what the isInteger() approach returns.
The following will be output to the internet browser console log:
true
false
false
In this example, the first output to the console log again authentic seeing that 25 is an integer.
The second output to the console log again false considering that 6.7 is no longer an integer.
The 0.33 output to the console log returned false in view that the string cost ’25’ is no longer a quantity and the isInteger() method does not convert the fee to a wide variety before checking out whether or not it is an integer.
Leave a Review