Lodash _.isSafeInteger() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Lang

Definition

Checks if value is a safe integer — an IEEE-754 double that represents an integer exactly (not a rounded unsafe integer). Part of Lodash 4.x Lang.

Note: Based on Number.isSafeInteger. Range is Number.MIN_SAFE_INTEGER … Number.MAX_SAFE_INTEGER (±(253 − 1)).

Syntax

Call _.isSafeInteger. Start with this line.

Lodash
_.isSafeInteger(value)
CallWhat it does
_.isSafeInteger(value)Primary signature.

Prefer import isSafeInteger from "lodash/isSafeInteger" when you want a smaller bundle.

Library declarations
Lodash
_.isSafeInteger(value)

Parameters

ParameterDescription
valueRequired. Value to test

Return Value

Return ValueDescription
*true / false

Lodash Examples

Example 1 — Official: Basic Checks

A small integer passes; float and Infinity fail.

Lodash
_.isSafeInteger(3);
// → true

_.isSafeInteger(3.2);
// → false

_.isSafeInteger(Infinity);
// → false
Try It Yourself

How It Works

  1. 3. Whole number inside the safe band → true.
  2. 3.2. Has a fractional part → not an integer.
  3. Infinity. Not a finite integer → false.
  4. Rule. Must be integer and in range.

Example 2 — Official: Safe Bounds

Edges of the safe range pass; one step outside fails.

Lodash
_.isSafeInteger(Number.MIN_SAFE_INTEGER);
// → true

_.isSafeInteger(Number.MIN_SAFE_INTEGER - 1);
// → false

_.isSafeInteger(Number.MAX_SAFE_INTEGER);
// → true

_.isSafeInteger(Number.MAX_SAFE_INTEGER + 1);
// → false
Try It Yourself

How It Works

  1. MIN / MAX. Inclusive bounds are still safe.
  2. Outside. ±1 past the edge is unsafe.
  3. Why. Doubles lose exact integer spacing past 253.
  4. Tip. Prefer BigInt for huge whole numbers.

Example 3 — Common Rejections

NaN, null, and objects are never safe integers.

Lodash
_.isSafeInteger(NaN);
// → false

_.isSafeInteger(null);
// → false

_.isSafeInteger({});
// → false

_.isSafeInteger(-0);
// → true   // still an integer 0
Try It Yourself

How It Works

  1. NaN / null / {}. Not number integers → false.
  2. -0. Treated as integer zero → true.
  3. Strict. Only real number values can pass.
  4. Validate. Great for IDs and counts that must stay exact.

Example 4 — Strings Need Conversion

Numeric strings fail until you convert them.

Lodash
_.isSafeInteger('3');
// → false

_.isSafeInteger(Number('3'));
// → true
Try It Yourself

How It Works

  1. No coerce. '3' is a string → false.
  2. Number(). Converts to the number 3.
  3. Then check. Now it passes as a safe integer.
  4. Careful. Number('3.2') still fails the integer test.

Example 5 — isSafeInteger vs isInteger

Large magnitudes can be integers but not safe.

Lodash
var n = Number.MAX_SAFE_INTEGER + 1;

_.isInteger(n);
// → true

_.isSafeInteger(n);
// → false
Try It Yourself

How It Works

  1. isInteger. Only asks “no fractional part?”.
  2. Past max. Value is still an integer-shaped double.
  3. isSafeInteger. Also enforces the safe band → false.
  4. Pick. Need exact counting / IDs → prefer safe check.

Browser & Runtime Support

_.isSafeInteger is a Lodash 4.x Lang helper based on Number.isSafeInteger. It runs anywhere Lodash runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash.

✓ Stable · Lodash 4.x

_.isSafeInteger()

Available in [email protected] full builds and the lodash/isSafeInteger modular import. Native Number.isSafeInteger is supported in all modern engines; Lodash provides a consistent API and polyfill-style behavior via its build.

100% With Lodash 4.x
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
_.isSafeInteger Lodash 4.x+

Bottom line: Safe for production once Lodash is loaded. Prefer import isSafeInteger from "lodash/isSafeInteger" for smaller bundles. Use it whenever counts or IDs must remain exact in JavaScript Numbers.

Frequently Asked Questions

_.isSafeInteger(value) returns true when value is an integer that fits exactly in an IEEE-754 double — between Number.MIN_SAFE_INTEGER and Number.MAX_SAFE_INTEGER inclusive.
An integer that round-trips exactly as a JavaScript Number. The range is -(2^53 - 1) … 2^53 - 1 (±9007199254740991).
Lodash does not coerce strings. Convert with Number(value) first when input arrives as text.
isInteger only checks integer-ness. isSafeInteger also rejects magnitudes outside the safe range (for example Number.MAX_SAFE_INTEGER + 1).
Yes in spirit — Lodash documents it as based on Number.isSafeInteger. Prefer the Lodash helper for consistent Lodash-style checks and modular imports.
Use import isSafeInteger from "lodash/isSafeInteger" or require("lodash/isSafeInteger") for tree-shaking friendly bundles. Full build: import _ from "lodash" then _.isSafeInteger.

Next: _.isSet()

Check whether a value is an ES6 Set instance.

_.isSet() 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.

10 people found this page helpful