.isInteger()

The Number.isInteger() method is a part of the Number class in JavaScript.

It accepts a single argument, value, and returns true if the passed argument is an integer, and returns false otherwise.

Syntax

Number.isInteger(value);
  • value (required): The value to check.

Examples

To verify if a value is an integer or not:

const x = 13 / 5;
// x = 2.6
console.log(Number.isInteger(x));
// Output: false
const y = 10 / 5;
// y = 2
console.log(Number.isInteger(y));
// Output: true

The above example passes an integer and a decimal value into Number.isInteger() method, to verify if the value is an integer or not. Then, the result is printed.

Codebyte Example

Code
Output
Loading...

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn JavaScript on Codecademy