check integer value in javascript code example

Example 1: javascript is number an integer

Number.isInteger(value)

//returns a Boolean

Example 2: javascript check if a value is a integer number

Number.isInteger(123) //true
Number.isInteger(-123) //true
Number.isInteger(5-2) //true
Number.isInteger(0) //true
Number.isInteger(0.5) //false
Number.isInteger('123') //false
Number.isInteger(false) //false
Number.isInteger(Infinity) //false
Number.isInteger(-Infinity) //false
Number.isInteger(0 / 0) //false

Example 3: To check if a value is a number in JavaScript

const value = 2
isNaN(value) //false
isNaN('test') //true
isNaN({}) //true
isNaN(1.2) //false

Tags:

Misc Example