JavaScript Number.isSafeInteger() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Method

Definition

Number.isSafeInteger(value) returns true only when value is an integer in the safe range Number.MIN_SAFE_INTEGER … Number.MAX_SAFE_INTEGER (±(253 − 1)). It is a static method (ES2015) and does not coerce types.

Pass the required arguments shown below. Check return values and browser support before you rely on the result.

Syntax

Call Number.isSafeInteger. Start with this line.

JavaScript
Number.isSafeInteger(value)
CallWhat it does
Number.isSafeInteger(value)Primary signature.
Number.isSafeInteger(...)Call with the arguments your case needs.

Built into JavaScript. Call Number.isSafeInteger(...) on the Number constructor — no import required.

Library declarations
JavaScript
Number.isSafeInteger(value)

Parameters

ParameterDescription
valueRequired. Any value to test

Return Value

Return ValueDescription
*true or false

JavaScript Examples

Example 1 — Safe Integers Pass

Everyday integers and the max/min safe limits all pass.

JavaScript
console.log(Number.isSafeInteger(3));                 // true
console.log(Number.isSafeInteger(-100));              // true
console.log(Number.isSafeInteger(2 ** 53 - 1));       // true
console.log(Number.isSafeInteger(-(2 ** 53 - 1)));    // true
Try It Yourself

How It Works

  1. Small integers. 3 and -100 are whole numbers well inside the safe range.
  2. Max boundary. 2 ** 53 - 1 equals Number.MAX_SAFE_INTEGER → still safe.
  3. Min boundary. The negative twin -(2 ** 53 - 1) is MIN_SAFE_INTEGER.
  4. Use case. Good guard before IDs, counters, or index math that must stay exact.

Example 2 — Just Outside the Safe Range

2 ** 53 is still an integer value — but not a safe one.

JavaScript
console.log(Number.isSafeInteger(2 ** 53));     // false
console.log(Number.isInteger(2 ** 53));         // true
console.log((2 ** 53) + 1 === (2 ** 53));      // true — precision loss!
Try It Yourself

How It Works

  1. Outside the range. 2 ** 53 is one past MAX_SAFE_INTEGER → isSafeInteger is false.
  2. Still an integer. Number.isInteger(2 ** 53) stays true — different question.
  3. Neighbors collide. Adding 1 does not change the stored value — exact math breaks.
  4. Takeaway. Prefer isSafeInteger when uniqueness of consecutive integers matters.

Example 3 — Floats and Strings Fail

Non-integers and non-numbers are rejected — no coercion.

JavaScript
console.log(Number.isSafeInteger(3.1));          // false
console.log(Number.isSafeInteger("3"));          // false
console.log(Number.isSafeInteger(Number("3")));  // true
console.log(Number.isSafeInteger(NaN));          // false
Try It Yourself

How It Works

  1. Floats fail. 3.1 has a fractional part → not an integer.
  2. No coercion. "3" is a string → false.
  3. Parse first. Number("3") yields a safe integer → true.
  4. Specials fail. NaN and Infinity are never safe integers.

Browser & Runtime Support

Number.isSafeInteger() is part of ES2015 and is Baseline Widely available in modern browsers and Node.js.

✓ Baseline · ES2015

Number.isSafeInteger()

Supported in Chrome, Firefox, Safari, Edge, and Node.js for years. Safe for modern apps without a polyfill.

98% Modern browser support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
Number.isSafeInteger Excellent

Bottom line: Use Number.isSafeInteger for new code. Fall back to a polyfill only if you must support very old environments.

Frequently Asked Questions

Number.isSafeInteger(value) returns true only when value is an integer in the safe range from Number.MIN_SAFE_INTEGER to Number.MAX_SAFE_INTEGER (±(2^53 − 1)). Example: Number.isSafeInteger(3) is true; Number.isSafeInteger(2 ** 53) is false.
Yes. Call it on Number itself: Number.isSafeInteger(x). Do not call it on a number instance like (5).isSafeInteger() — that is not the Number API.
A safe integer can be exactly represented in IEEE-754 double precision, and nearby integers do not round to the same floating-point value. The range is −9007199254740991 to 9007199254740991.
Number.isInteger(2 ** 53) is true, but Number.isSafeInteger(2 ** 53) is false. Every safe integer is an integer, but not every integer Number value is safe.
No. Number.isSafeInteger("3") is false. Parse first if you need to accept text: Number.isSafeInteger(Number("3")).
It is Baseline Widely available (ES2015) and supported in every modern browser and Node.js.

Next: parseInt()

Learn how to parse a string into an integer with an optional radix.

parseInt() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful