Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

Number.isInteger

Checks whether a value is an integer.

Available since: ES2015

Syntax

Number.isInteger(value)

Parameters

ParameterTypeDescription
valueanyThe 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
false

Strings are not converted:

console.log(Number.isInteger('5'));
console.log(Number.isInteger(5.0));

Output:

false
true

Notes

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.

Thanks for reading!

Donate to the site — we work hard for you.