.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.6console.log(Number.isInteger(x));// Output: false
const y = 10 / 5;// y = 2console.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.