Validation/Since
1.38.0isInteger
Checks whether a value is an integer number.
isInteger(value):booleanBehavior
The function delegates directly to Number.isInteger. It returns true only when the value is a number whose value is an integer.
Type guard
The function is a TypeScript type guard. When it returns true, TypeScript narrows the value from unknown to number.
Parameters
valueunknownrequiredThe value to check.
Returns
booleanReturns true when the value is an integer number; otherwise returns false.
Examples
01
Integer values
Returns true for positive, negative, and zero integer values.
TypeScript
isInteger(42);
// true
isInteger(-10);
// true
isInteger(0);
// true02
Decimal values
Decimal numbers are not considered integers.
TypeScript
isInteger(4.5);
// false
isInteger(-2.75);
// false03
Non-number values
Strings, booleans, null, and other non-number values return false.
TypeScript
isInteger("42");
// false
isInteger(true);
// false
isInteger(null);
// false04
Special numbers
NaN and Infinity are not integers.
TypeScript
isInteger(NaN);
// false
isInteger(Infinity);
// falseBuilt with@cyref/js·Official documentation