Underscore.js _.isEqual() Method

Beginner
5 min read
Updated: Nov 2026
4 examples
Object

Definition

Performs an optimized deep comparison between two values (official Underscore docs). Same contents → true, even when the references differ.

Pass the required arguments shown below. Underscore object helpers usually return a new value — check whether the source object is mutated.

Syntax

Call _.isEqual. Start with this line.

Underscore
_.isEqual(object, other)
CallWhat it does
_.isEqual(object, other)Primary signature.
_.isEqual(...)Call with the arguments your case needs.

Load Underscore with import _ from "underscore" (or the UMD CDN build) so these helpers are available as _.

Library declarations
Underscore
_.isEqual(object, other)

Parameters

ParameterDescription
objectRequired. First value
otherRequired. Second value

Return Value

Return ValueDescription
*true or false

Underscore.js Examples

Example 1 — Official Docs

Two look-alike objects: == is false; _.isEqual is true.

Underscore
var stooge = { name: "moe", luckyNumbers: [13, 27, 34] };
var clone  = { name: "moe", luckyNumbers: [13, 27, 34] };

console.log(stooge == clone);          // false
console.log(_.isEqual(stooge, clone)); // true
Try It Yourself

How It Works

  1. Two objects. Same shape and nested array, different references.
  2. == fails. Identity comparison sees two distinct objects.
  3. isEqual walks inside. Keys and nested values match → true.
  4. Takeaway. Use deep equality when contents matter.

Example 2 — Arrays by Contents and Order

Same order matches. Different order does not. === still compares identity.

Underscore
console.log(_.isEqual([1, 2, 3], [1, 2, 3])); // true
console.log(_.isEqual([1, 2, 3], [1, 3, 2])); // false
console.log([1, 2, 3] === [1, 2, 3]);         // false
Try It Yourself

How It Works

  1. Same sequence. Index-by-index match → true.
  2. Swapped items. Order differs → false.
  3. ===. Two array literals are different references → false.
  4. Rule. Array order matters for deep equality.

Example 3 — Extra Keys Fail

Deep equality requires the same shape. Partial match tools allow extras.

Underscore
var moe = { name: "moe", age: 32 };

console.log(_.isEqual({ name: "moe" }, moe)); // false
console.log(_.matcher({ name: "moe" })(moe)); // true
Try It Yourself

How It Works

  1. Smaller object. Missing age on one side → not equal.
  2. isEqual fails. Shapes must match completely.
  3. matcher passes. _.matcher only requires the listed properties.
  4. Pick the tool. Full equality vs partial match.

Example 4 — NaN and Dates

_.isEqual treats NaN as equal to NaN, and compares Dates by time.

Underscore
console.log(_.isEqual(NaN, NaN));                 // true
console.log(NaN === NaN);                         // false
console.log(_.isEqual(new Date(0), new Date(0))); // true
console.log(_.isEqual(new Date(0), new Date(1))); // false
Try It Yourself

How It Works

  1. NaN special case. Underscore treats both NaNs as equal.
  2. === does not. Native strict equality fails for NaN.
  3. Same timestamp. Dates with equal getTime() match.
  4. Different times. Fail the deep check.

Browser & Runtime Support

_.isEqual ships with Underscore.js (1.x). It runs anywhere Underscore runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install underscore.

✓ Stable · Underscore 1.x

_.isEqual()

Available in [email protected] (UMD / ESM). Works in evergreen browsers and current Node LTS when Underscore is loaded.

100% With Underscore 1.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
_.isEqual Underscore 1.x+

Bottom line: Safe for production once Underscore is on the page or in your bundle. Not a native browser API — load Underscore first. Prefer a pinned CDN version (e.g. [email protected]).

Frequently Asked Questions

_.isEqual(object, other) performs a deep comparison and returns true when the two values should be considered equal — same contents, not just the same reference. Two different objects with the same keys and nested values are equal.
=== is true for objects only when both sides are the exact same object in memory. _.isEqual walks inside objects and arrays and compares their values. {a:1} === {a:1} is false; _.isEqual({a:1}, {a:1}) is true.
No. Both sides must have the same own enumerable keys and matching values. An extra key makes _.isEqual return false. For a partial match, use _.matcher or _.isMatch.
Yes. NaN === NaN is false in JavaScript, but _.isEqual(NaN, NaN) is true. Date objects are compared by their millisecond value, not by reference.
Yes. Arrays are compared index by index, so [1,2,3] is not equal to [1,3,2]. For plain objects, key order does not matter.
No. It is a stable Underscore 1.x helper for deep equality checks. It does not mutate the values you pass in.

Next: _.isMatch()

Test whether an object contains a subset of properties — partial match without full equality.

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