The Number.isInteger() method determines whether a value an integer.
The Number.isInteger() method determines whether a value an integer.
This method returns true if the value is of the type Number, and a whole number. Otherwise it returns false.
Number.isInteger(value)
Parameter | Require | Description |
---|---|---|
value | Required. | The value to be tested |
A Boolean. Returns true if the value is an integer Number, otherwise it returns false
Check whether a value is an integer:
var res = ""; res = res + Number.isInteger(123) + ": 123\n"; res = res + Number.isInteger(-123) + ": -123\n"; res = res + Number.isInteger(5-2) + ": 5-2\n"; res = res + Number.isFinite(0) + ": 0\n"; res = res + Number.isInteger(0.5) + ": 0.5\n"; res = res + Number.isInteger('123') + ": '123'\n"; res = res + Number.isInteger(false) + ": false\n"; res = res + Number.isInteger(Infinity) + ": Infinity\n"; res = res + Number.isInteger(-Infinity) + ": -Infinity\n"; res = res + Number.isInteger(0 / 0) + ": 0 / 0\n"; console.log(res);/*w w w . j a v a 2 s.c o m*/