Lodash _.lt() method

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

What you’ll learn

  • How _.lt(value, other) resolves to a clean true/false.
  • Why string-vs-string skips number coercion while mixed pairs don’t.
  • What happens with null, undefined, and NaN.
  • When to prefer _.lt over the raw < operator (and when not).

Prerequisites

You’re comfortable with JavaScript’s < operator and the basics of type coercion (Number(value)).

  • You know that NaN < anything is always false.
  • Try-it labs load lodash from the CDN.

Overview

Lodash wires _.lt through a relational-operation helper: strings on both sides → lexicographic <, otherwise both arguments are coerced with Number(...) first. Strict-equal values return false.

Number-friendly

Mixed types coerce: _.lt('5', 10)true.

String-aware

Two strings stay strings — lexicographic order, so '10' < '9' is true.

NaN-aware

undefinedNaN → comparison is always false.

Syntax

javascript
_.lt(value, other)
  • value: the first value to compare.
  • other: the second value to compare against.
  • Returns: true if value is less than other; otherwise false.
1

Number comparison basics

The lodash docs trio: smaller wins, equal returns false, bigger returns false.

javascript
import lt from "lodash/lt";

console.log(
  "1 < 3: " + lt(1, 3) + "\n" +    // true  (lodash docs)
  "3 < 3: " + lt(3, 3) + "\n" +    // false (lodash docs)
  "3 < 1: " + lt(3, 1)              // false (lodash docs)
);
Try it Yourself
2

Strings stay lexicographic

When both args are strings, lodash skips number coercion—so digit strings compare character by character.

javascript
import lt from "lodash/lt";

console.log(
  "apple < banana: " + lt("apple", "banana") + "\n" +  // true  (a < b)
  "apple < Apple:  " + lt("apple", "Apple") + "\n" +    // false (uppercase has lower code point)
  "'10' < '9':      " + lt("10", "9")                 // true  (lexicographic, '1' < '9')
);
Try it Yourself
3

Coercion: nullish & mixed types

When the pair isn’t two strings, lodash calls Number(...) on each side. null becomes 0, undefined becomes NaN.

javascript
import lt from "lodash/lt";

console.log(
  "'5' < 10:     " + lt("5", 10) + "\n" +          // true (Number('5') = 5)
  "null < 1:      " + lt(null, 1) + "\n" +           // true (Number(null) = 0)
  "undefined < 1: " + lt(undefined, 1) + "\n" +     // false (NaN)
  "NaN < 1:       " + lt(NaN, 1)                     // false (NaN never compares)
);
Try it Yourself

📋 _.lt vs related operators

API / patternBehavior
_.lt(a, b)String pair → lexicographic; otherwise both coerced to Number.
a < bNative operator—uses standard abstract relational comparison; behaviour is similar but never special-cases the string pair detection.
_.lte(a, b)Includes equality (<=).
_.gt(a, b)Mirror operation—greater than.

Pitfalls to avoid

Strings

Digit strings sort lexicographically

_.lt('10', '9') is true. Convert numeric strings to numbers first if you need numeric order: _.lt(Number(a), Number(b)).

Undefined

undefined always loses

Number(undefined) is NaN, and any NaN comparison returns false. Guard for missing data instead of relying on _.lt to be truthy.

BigInt

BigInt throws

Lodash routes through Number(...), which can’t convert BigInts. Use the native < operator (1n < 2n) when working with arbitrary-precision integers.

❓ FAQ

When both args are strings, _.lt() uses string < (lexicographic). Otherwise both are coerced to numbers via Number(...). Plain < doesn't take that conditional path.
null coerces to 0 with Number(null), so the call becomes 0 < 1.
Number(undefined) is NaN, and any comparison with NaN returns false.
No. BigInt cannot be converted to Number, so _.lt(1n, 2n) throws a TypeError. Compare BigInts with the native < operator instead.

Summary

  • Purpose: return true when value < other with predictable coercion.
  • Remember: two strings stay strings; otherwise both sides go through Number().
  • Next: continue with the Lodash _.lte() index, where _.lte and _.gt live.
Did you know?

Lodash special-cases string + string pairs—_.lt('10', '9') returns true because both stay as strings and JavaScript compares them lexicographically. Mix in a number and lodash coerces both with Number(...), so _.lt('10', 9) returns false.

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.

5 people found this page helpful