Home

Check if a number is Integer in JavaScript

To check whether a given number is Integer, we have a isInteger method available on Number object in JavaScript.

The isInteger method will always return a Boolean value.

Number.isInteger(0)          // true
Number.isInteger(245)        // true
Number.isInteger(-123)       // true

Number.isInteger(12.145)     // false
Number.isInteger('1274')     // false
Number.isInteger('booo')     // false
Number.isInteger(NaN)        // false
Number.isInteger(Infinity)   // false
Number.isInteger(-Infinity)  // false
Number.isInteger(true)       // false
Number.isInteger(false)      // false

Note: The Infinity,-Infinity and NaN will return false when used with Number.isInteger()



Last Updated on

Next Post: Rules vs Guidelines →

Comments