Number.isSafeInteger
Determines 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
Syntax
Number.isSafeInteger(testValue)Parameters
| Parameter | Type | Description |
|---|---|---|
| testValue | any | The value to be tested |
Return Value
true if the value is a safe integer, false otherwise
Examples
console.log(Number.isSafeInteger(42)); // true
console.log(Number.isSafeInteger(9007199254740991)); // true (MAX_SAFE_INTEGER)console.log(Number.isSafeInteger(9007199254740992)); // false
console.log(Number.isSafeInteger(3.14)); // falseconst MAX = Number.MAX_SAFE_INTEGER;
console.log(MAX); // 9007199254740991
console.log(Number.isSafeInteger(MAX)); // true
console.log(Number.isSafeInteger(MAX + 1)); // falseUnderstanding Number.isSafeInteger
The Number.isSafeInteger method in JavaScript determines 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. 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.isSafeInteger(testValue). It accepts 1 parameter: testValue. When called, it returns true if the value is a safe integer, false otherwise. Understanding when and how to use isSafeInteger() helps you write more expressive, readable code.
Common use cases for Number.isSafeInteger include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like number-isinteger, number-isfinite, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for Number.isSafeInteger 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
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.