Last Updated : 10 Jan, 2025
The Number.isInteger() method in JavaScript is useful for checking whether a number is a whole number or not.
Syntax:Number.isInteger(value);Parameters:
value
: The value to be checked.It 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, it returns false.
Example 1: This example checks for some values if they are integers or not using the Number.isInteger() method in JavaScript.
JavaScript
console.log(Number.isInteger(-2));
console.log(Number.isInteger(0));
console.log(Number.isInteger(2));
Example 2: Here, a negative number is passed as an argument. This code logs `false` because `-2.56` is not an integer. `Number.isInteger()` returns `false` for non-integer numeric values.
JavaScript
console.log(Number.isInteger(-2.56));
Example 3: Here, a string is passed as an argument. This code logs "Output : false" because "hi" is not a number and Number.isInteger() returns false for non-numeric values.
JavaScript
console.log("Output : " + Number.isInteger("hi"));
Supported Browsers:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4