Number.isInteger
Checks whether a value is an integer.
Available since: ES2015
Syntax
Number.isInteger(value)Parameters
| Parameter | Type | Description |
|---|---|---|
| value | any | The value to check. |
Return value
booleantrue if the value is a number without a fractional part.
Examples
Whole and fractional:
console.log(Number.isInteger(5));
console.log(Number.isInteger(5.5));Output:
true
falseStrings are not converted:
console.log(Number.isInteger('5'));
console.log(Number.isInteger(5.0));Output:
false
trueNotes
5.0 and 5 are the same number in JavaScript, so 5.0 counts as an integer.
See also
- Number.isSafeInteger — Checks that an integer is within the range where it is stored exactly.
- Number.isFinite — Checks that a value is a finite number (not NaN and not Infinity).
- Math.trunc — Drops the fractional part of a number.
In the tutorial
- Numbers — Numbers in JavaScript — integers and fractions, rounding, the Math object, toFixed and the special values Infinity and NaN.