The Wayback Machine - http://web.archive.org/web/20220807192621/https://www.geeksforgeeks.org/javascript-number-isinteger-function/amp/

JavaScript Number.isInteger( ) Method

Below is the example of Number.isInteger( ) Method.




<script type="text/javascript">
    document.write(Number.isInteger(-2)+"<br>");
    document.write(Number.isInteger(0)+"<br>");
    document.write(Number.isInteger(2));         
</script>

true
true
true

The Number.isInteger() method in JavaScript is used to check whether the value passed to it is an integer or not. It returns true if the passed value is an integer, otherwise, it returns false. 



Syntax:

Number.isInteger(value)

Parameters: This method accepts a single parameter value which specifies the number which the user wants to check for integer. 

Return Value: The number.isInteger() method returns a boolean value ,i.e. either true or false. It will return true if the passed value is of the type Number and an integer, else it returns false. The below examples illustrates the Number.isInteger() method in JavaScript:




<script type="text/javascript">
    document.write(Number.isInteger(-2));
    document.write(Number.isInteger(-2.56));         
</script>

Output:

true
false




<script type="text/javascript">
    document.write(Number.isInteger(2));         
</script>

Output:

true




<script type="text/javascript">
    document.write(Number.isInteger(0));         
</script>

Output:

true




<script type="text/javascript">
    document.write(Number.isInteger(2.03));         
</script>

Output:

false




<script type="text/javascript">
    document.write("Output : " + Number.isInteger("hi"));         
</script>

Output:

false

Supported Browsers:

JavaScript is best known for web page development but it is also used in a variety of non-browser environments. You can learn JavaScript from the ground up by following this JavaScript Tutorial and JavaScript Examples.




Article Tags :