Number.isInteger
Determines whether the passed value is an integer
Syntax
Number.isInteger(value)Parameters
| Parameter | Type | Description |
|---|---|---|
| value | any | The value to be tested |
Return Value
true if the value is an integer, false otherwise
Examples
console.log(Number.isInteger(42)); // true
console.log(Number.isInteger(42.0)); // true
console.log(Number.isInteger(42.5)); // falseconsole.log(Number.isInteger('42')); // false
console.log(Number.isInteger(Infinity)); // false
console.log(Number.isInteger(NaN)); // falsefunction validateAge(age: unknown): age is number {
return typeof age === 'number' && Number.isInteger(age) && age > 0;
}Understanding Number.isInteger
The Number.isInteger method in JavaScript determines whether the passed value is an integer. It belongs to the Number object and is one of the most widely used methods for working with number values in modern JavaScript and TypeScript applications.
The method signature is Number.isInteger(value). It accepts 1 parameter: value. When called, it returns true if the value is an integer, false otherwise. Understanding when and how to use isInteger() helps you write more expressive, readable code.
Common use cases for Number.isInteger include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like number-issafeinteger, number-isfinite, number-isnan, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for Number.isInteger is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
Number.isSafeIntegerDetermines whether the provided value is a number that is a safe integer, meaning it can be exactly represented as a double-precision floating-point number
Number.isFiniteDetermines whether the passed value is a finite number — not Infinity, -Infinity, or NaN
Number.isNaNDetermines whether the passed value is NaN and its type is Number, providing a more robust version of the original global isNaN()
More Number Methods
Other methods in the Number object
Related Tools
More Number Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.