Lodash _.eq() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Lang

Definition

Performs a SameValueZero comparison between two values to decide if they are equivalent. Part of Lodash Lang since 4.0.0 (stable — not deprecated). Note: same rule as Map / Set keys — NaN equals NaN, and +0 equals -0.

Pass the value you want to inspect or convert. Read the return type carefully before you use the result.

Syntax

Call _.eq. Start with this line.

Lodash
_.eq(value, other)
CallWhat it does
_.eq(value, other)Primary signature.
_.eq(value)Check, compare, clone, or convert a value.

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

Library declarations
Lodash
_.eq(value, other)

Parameters

ParameterDescription
valueRequired. First value to compare
otherRequired. Second value to compare

Return Value

Return ValueDescription
*true if equivalent, else false

Lodash Examples

Example 1 — Official: Same vs Different Object Refs

Objects match only when they are the same reference.

Lodash
var object = { a: 1 };
var other = { a: 1 };

console.log(_.eq(object, object)); // true
console.log(_.eq(object, other));  // false
Try It Yourself

How It Works

  1. Same ref. object compared to itself → true.
  2. Look-alike. other has the same shape but is a new object.
  3. Reference. Different identity → false.
  4. Tip. Need content equality? Use _.isEqual.

Example 2 — Official: Primitive String vs Object("a")

A string primitive is not the same as a String object wrapper.

Lodash
console.log(_.eq("a", "a"));         // true
console.log(_.eq("a", Object("a"))); // false
Try It Yourself

How It Works

  1. Primitives. Two "a" strings match → true.
  2. Boxed. Object("a") is an object, not a primitive string.
  3. Types differ. SameValueZero does not coerce → false.
  4. Same as ===. No type conversion happens.

Example 3 — Official: NaN Equals NaN

The main reason to prefer _.eq over bare ===.

Lodash
console.log(NaN === NaN);   // false
console.log(_.eq(NaN, NaN)); // true
Try It Yourself

How It Works

  1. Strict. JavaScript defines NaN !== NaN.
  2. SameValueZero. Lodash treats both as matching.
  3. Use. Safe for lookups and dedupe where NaN appears.
  4. Map/Set. Same rule as key equality in those collections.

Example 4 — +0 and -0 Are Equal

Unlike Object.is, signed zeros match under SameValueZero.

Lodash
console.log(_.eq(0, -0));      // true
console.log(Object.is(0, -0)); // false
console.log(0 === -0);         // true
Try It Yourself

How It Works

  1. eq. SameValueZero → 0 and -0 match.
  2. Object.is. SameValue → they differ.
  3. ===. Also treats them as equal.
  4. Pick. Need to distinguish zeros? Use Object.is, not _.eq.

Example 5 — eq vs isEqual

Reference check versus deep content check.

Lodash
var a = { x: 1 };
var b = { x: 1 };

console.log(_.eq(a, b));      // false
console.log(_.isEqual(a, b)); // true
Try It Yourself

How It Works

  1. eq. Different object identities → false.
  2. isEqual. Walks nested values → same shape → true.
  3. Cost. eq is O(1); isEqual grows with structure size.
  4. Pick. Identity / primitives → eq; deep trees → isEqual.

Browser & Runtime Support

_.eq is a Lodash 4.x Lang helper (since 4.0.0). It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash. Native engines expose related ideas via ===, Object.is, and SameValueZero in Map/Set, but not this helper by name.

✓ Stable · Lodash 4.0.0+

_.eq()

Available in [email protected] full builds and the lodash/eq modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.

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
_.eq Lodash 4.0.0+

Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import eq from "lodash/eq" for smaller builds. Not a native browser API — load Lodash first.

Frequently Asked Questions

_.eq(value, other) performs a SameValueZero comparison. It returns true when the values are equivalent under that rule — including NaN === NaN and +0 === -0.
Almost, but not for NaN. Strict equality makes NaN !== NaN. _.eq(NaN, NaN) is true. Both treat +0 and -0 as equal.
No. Object.is follows SameValue and treats +0 and -0 as different. _.eq uses SameValueZero, so +0 and -0 are equal.
No. Objects and arrays are compared by reference, like ===. Use _.isEqual for deep structural equality.
It is the same equality rule used by Map and Set key matching — NaN matches NaN, and signed zeros match each other.
Use import eq from "lodash/eq" or require("lodash/eq") so bundlers can tree-shake unused Lodash code. Full build: import _ from "lodash" then _.eq.

Next: _.gt()

Check whether one value is strictly greater than another.

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