.isInteger()

Published Oct 12, 2021Updated Oct 13, 2021
Contribute to Docs

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

us
Visit us
code
Hide code
Code
Output
Hide output
Hide output
Loading...

All contributors

Looking to contribute?

Learn JavaScript on Codecademy