Number

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

JavaScript
Number.isSafeInteger(testValue)

Parameters

ParameterTypeDescription
testValueanyThe value to be tested

Return Value

true if the value is a safe integer, false otherwise

Examples

Basic Usage
console.log(Number.isSafeInteger(42)); // true
console.log(Number.isSafeInteger(9007199254740991)); // true (MAX_SAFE_INTEGER)
Practical Example
console.log(Number.isSafeInteger(9007199254740992)); // false
console.log(Number.isSafeInteger(3.14)); // false
Advanced Usage
const MAX = Number.MAX_SAFE_INTEGER;
console.log(MAX); // 9007199254740991
console.log(Number.isSafeInteger(MAX)); // true
console.log(Number.isSafeInteger(MAX + 1)); // false

Understanding 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.