CyrefJS
CCyrefJS
فا
Back to documentation
Validation/Since 1.38.0

isInteger

Checks whether a value is an integer number.

isInteger(value):boolean

Behavior

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

valueunknownrequired

The value to check.

Returns

boolean

Returns 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);
// true
02

Decimal values

Decimal numbers are not considered integers.

TypeScript
isInteger(4.5);
// false

isInteger(-2.75);
// false
03

Non-number values

Strings, booleans, null, and other non-number values return false.

TypeScript
isInteger("42");
// false

isInteger(true);
// false

isInteger(null);
// false
04

Special numbers

NaN and Infinity are not integers.

TypeScript
isInteger(NaN);
// false

isInteger(Infinity);
// false
Built with@cyref/js·Official documentation