Lodash _.gt() method

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

What you’ll learn

  • How _.gt(value, other) maps to JavaScript’s > comparison.
  • Ordering for numbers, strings, and Date values.
  • Why NaN and many object pairs yield false.
  • When to pair _.gt with _.gte, _.lt, and _.lte.

Prerequisites

Comfort with the > operator and a rough sense of when JavaScript coerces values during comparisons.

  • You can read numeric and string ordering examples.
  • You can open Try-it labs in the browser.

Overview

_.gt is a small, readable wrapper around strict greater-than tests. Use it in predicates and comparators when you want lodash-style imports and a name that reads naturally in English.

Numeric order

Compare magnitudes the same way > does after standard numeric conversion rules.

String ordering

Lexicographic by UTF-16 code units—fine for ASCII tokens, not for localized words.

NaN guards

Any comparison with NaN is false; validate inputs when data might be invalid.

Syntax

javascript
_.gt(value, other)
  • value: left-hand side of the comparison.
  • other: right-hand side of the comparison.
  • Returns: true if value > other under JavaScript rules; otherwise false.
1

Numbers and strings

For finite numbers, ordering matches ordinary arithmetic. For strings, comparison is lexicographic.

javascript
import gt from "lodash/gt";

gt(5, 3);             // true
gt(3, 5);             // false
gt("b", "a");         // true
Try it Yourself
2

Dates and decimals

Date objects are compared via their time values. Decimals follow numeric ordering.

javascript
import gt from "lodash/gt";

var later = new Date("2020-01-01");
var earlier = new Date("2019-12-31");

gt(later, earlier);   // true
gt(3.14, 3);          // true
Try it Yourself
3

Mixed types and coercion

Relational comparisons can coerce operands (for example string to number). Stay explicit in production code when types vary.

javascript
import gt from "lodash/gt";

gt(10, "9");          // true (numeric comparison path)
gt("10", 9);          // true
Try it Yourself

📋 _.gt vs _.gte vs _.lt

MethodMeaning
_.gt(a, b)a > b
_.gte(a, b)a >= b
_.lt(a, b)a < b
_.lte(a, b)a <= b

Pitfalls to avoid

NaN

Invalid numbers

_.gt(NaN, x) and _.gt(x, NaN) are always false.

Objects

Surprising object pairs

Plain objects convert via ToPrimitive; two {} values often both become [object Object], so _.gt({}, {}) is false.

Locales

Localized text

String ordering is not linguistically correct for user-visible sorting; use collation APIs when needed.

❓ FAQ

Yes. Lodash's gt uses the language's greater-than comparison, so you get the same truth value as the binary > operator for the same operands.
Any ordered comparison involving NaN is false in JavaScript, including > and <. Use Number.isFinite or explicit NaN checks when you need special handling.
Like > on strings: UTF-16 code unit lexicographic order, not locale-aware collation. For human sorting, use Intl.Collator or localeCompare with options.
Use _.gt when you want a named predicate for callbacks (filter, sort comparators) or consistent lodash-style imports alongside other lang helpers.

Summary

  • Purpose: strict greater-than in one named call.
  • Semantics: identical to the binary > operator for the same operands.
  • Next: explore more on Lodash _.gte().
Did you know?

_.gt delegates to the same relational comparison as the binary > operator: the result is true only when value > other after JavaScript's comparison rules (including coercion where the language allows it).

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