Lodash _.gte() method
What you’ll learn
- How
_.gte(value, other)maps to JavaScript’s>=comparison. - Why equal values return
true(unlike_.gt). - Ordering for numbers, strings, and
Datevalues. - How
NaNand coercion interact with inclusive bounds.
Prerequisites
Comfort with >= and the idea that inclusive comparisons treat equal operands as passing.
- You can read numeric and string ordering examples.
- You can open Try-it labs in the browser.
Overview
_.gte is the lodash helper for “at least” checks: minimums, floors, and deadlines where hitting the boundary value should still pass. It mirrors >=, so equality is included.
Inclusive bound
gte(a, b) when a === b or a > b—ideal for thresholds.
Same ordering rules
Numbers, strings, and dates follow the same comparison semantics as > and >=.
Still NaN-safe
Any comparison involving NaN is false; validate numeric inputs first.
Syntax
_.gte(value, other) - value: left-hand side of the comparison.
- other: right-hand side of the comparison.
- Returns:
trueifvalue >= otherunder JavaScript rules; otherwisefalse.
Numbers, equality, and strings
_.gte returns true when values are equal or the left side is larger. Lexicographic rules apply to strings.
import gte from "lodash/gte";
gte(5, 3); // true
gte(3, 3); // true (not true for _.gt)
gte(3, 5); // false
gte("b", "a"); // true Dates: later, equal, and earlier
Two Date objects with the same instant compare as equal, so _.gte passes; a later instant still compares greater.
import gte from "lodash/gte";
var later = new Date("2020-01-01");
var earlier = new Date("2019-12-31");
var sameAsLater = new Date("2020-01-01");
gte(later, earlier); // true
gte(later, sameAsLater); // true
gte(3.14, 3); // true Mixed types and coercion
Relational >= can coerce operands the same way as >. Prefer consistent types in application logic.
import gte from "lodash/gte";
gte(10, "9"); // true
gte("10", 9); // true
gte(9, 9); // true 📋 _.gte vs _.gt vs _.lte
| Method | Meaning |
|---|---|
_.gte(a, b) | a >= b (equal or greater) |
_.gt(a, b) | a > b (strictly greater) |
_.lte(a, b) | a <= b |
_.lt(a, b) | a < b |
Pitfalls to avoid
Need strictly greater?
Use _.gt when equality must fail (for example “must be above” a limit).
Invalid numbers
_.gte(NaN, x) is always false; do not rely on it for range checks on dirty data.
Localized text
String ordering is not linguistically correct for user-visible sorting; use collation APIs when needed.
❓ FAQ
Summary
- Purpose: greater-than-or-equal in one named call.
- Semantics: identical to the binary
>=operator for the same operands. - Next: explore more on Lodash _.isArguments().
_.gte matches the binary >= operator: it returns true when value >= other—so equal operands pass, unlike _.gt.
6 people found this page helpful
