Lodash _.isInteger() method

Beginner
⏱️ 6 min read
📚 Updated: May 2026
🎯 3 Code examples
🚀 3 Try-it labs
Lodash

What you’ll learn

  • How _.isInteger(value) mirrors Number.isInteger while fitting lodash pipelines.
  • Which numeric literals pass (whole primitives, including negatives and zero).
  • Why floats, special numbers, strings, and boxed numbers fail.
  • When to coerce input before calling lodash versus rejecting invalid types.

Prerequisites

You know JavaScript number primitives and the difference between 3 and "3".

  • You understand typeof versus boxed wrappers (new Number(1)).
  • Try-it labs load lodash from the CDN.

Overview

Use _.isInteger when validating counters, IDs parsed from APIs (already numeric), pagination bounds, or config fields that must be whole numbers—without accidental string acceptance.

Primitive numbers

typeof value === "number" gates everything else first.

Whole values

Equality with _.toInteger(value) rejects fractional parts safely.

No coercion

Strings and objects fail unless you normalize beforehand.

Syntax

javascript
_.isInteger(value)
  • value: any value to test.
  • Returns: true when value is a finite primitive number with no fractional part; otherwise false.
1

Positive and negative integers

Ordinary whole-number literals pass.

javascript
import isInteger from "lodash/isInteger";

console.log(
  "three: " + isInteger(3) + "\n" +       // true
  "negSeven: " + isInteger(-7)           // true
);
Try it Yourself
2

Floats, MIN_VALUE, and Infinity

Fractional math numbers and non-finite extremes fail lodash’s integer test.

javascript
import isInteger from "lodash/isInteger";

console.log(
  "float: " + isInteger(3.14) + "\n" +                     // false
  "minVal: " + isInteger(Number.MIN_VALUE) + "\n" +          // false
  "inf: " + isInteger(Infinity)                           // false
);
Try it Yourself
3

Zero, numeric strings, and boxed numbers

0 is an integer; strings and Number objects are not accepted as-is.

javascript
import isInteger from "lodash/isInteger";

console.log(
  "zero: " + isInteger(0) + "\n" +              // true
  "numericStr: " + isInteger("3") + "\n" +       // false
  "boxedNum: " + isInteger(Object(42))           // false
);
Try it Yourself

📋 _.isInteger vs related checks

APIBehavior
_.isInteger(x)Primitive number and mathematically integral (lodash aligns with Number.isInteger).
Number.isInteger(x)Same classification for finite integers; no string coercion.
_.isFinite(x)Broader—any finite number, including 3.5.
parseInt(str, 10)Parses strings; combine with separate validation—do not confuse with type guards.

Pitfalls to avoid

Forms

Query parameters

req.query.page is usually a string—call Number() (and guard NaN) before _.isInteger.

JSON

Already parsed numbers

After JSON.parse, numeric fields are already primitive numbers—lodash works on them without extra coercion.

Safe ints

Beyond Number precision

Very large literals may lose precision; integer detection still follows IEEE rules—use BigInt when required.

❓ FAQ

Lodash documents that it follows Number.isInteger semantics: only finite primitive numbers with no fractional part return true.
The value must pass typeof === "number" first—numeric strings are still strings until you coerce them with Number() or unary +.
Boxed numbers have typeof "object"; lodash intentionally rejects them.
MIN_VALUE is the smallest positive subnormal float—not an integral mathematical integer—so both lodash and Number.isInteger reject it.

Summary

  • Purpose: detect finite primitive numbers without a fractional component.
  • Remember: coerce or reject strings before lodash sees them.
  • Next: explore more on Lodash _.isLength().
Did you know?

_.isInteger is implemented as typeof value === "number" plus value == _.toInteger(value)—so values must already be numbers; coerced strings like "42" and Object(7) fail immediately.

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.

6 people found this page helpful