Underscore.js _.identity() Method

Beginner
5 min read
Updated: Nov 2026
4 examples
Utility

Definition

Returns the same value that is used as the argument — in math, f(x) = x (official Underscore docs).

Pass the required arguments shown below. Underscore utility helpers usually return a new value or function — check edge cases before you ship.

Syntax

Call _.identity. Start with this line.

Underscore
_.identity(value)
CallWhat it does
_.identity(value)Primary signature.
_.identity(...)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
_.identity(value)

Parameters

ParameterDescription
valueRequired. Whatever you want returned unchanged

Return Value

Return ValueDescription
*The same value (same reference)

Underscore.js Examples

Example 1 — Official Stooge Check

The same object reference comes back — strict equality is true.

Underscore
var stooge = { name: 'moe' };

stooge === _.identity(stooge);
// → true
Try It Yourself

How It Works

  1. Build an object. stooge is { name: 'moe' }.
  2. Pass it through. _.identity(stooge) returns that argument.
  3. Compare with ===. Same reference → true.
  4. Not a clone. No new object is created.

Example 2 — Filter Truthy Values

Use _.identity as a predicate: falsy items are dropped.

Underscore
_.filter([0, 1, false, 2, '', 3], _.identity);
// → [1, 2, 3]

// Same idea as keeping only truthy items
Try It Yourself

How It Works

  1. Each item. Filter calls _.identity(item).
  2. Truthy keep. 1, 2, 3 stay.
  3. Falsy drop. 0, false, '' are removed.
  4. Shortcut. A named pass-through doubles as a truthiness check.

Example 3 — Pass-Through with Map

Mapping with identity leaves every element unchanged (default-iteratee idea).

Underscore
_.map([1, 2, 3], _.identity);
// → [1, 2, 3]

var nums = [10, 20];
_.map(nums, _.identity) === nums;
// → false  (new array; same item values)
Try It Yourself

How It Works

  1. Map each item. The iteratee returns the item itself.
  2. Same values. You get [1, 2, 3] again.
  3. New array. _.map still builds a fresh outer array.
  4. Default idea. When Underscore needs a no-transform iteratee, this is it.

Example 4 — _.identity vs _.constant

Identity returns now; constant returns a function for later.

Underscore
_.identity(10);
// → 10

var ten = _.constant(10);
ten();
// → 10

typeof _.identity(10);   // "number"
typeof _.constant(10);   // "function"
Try It Yourself

How It Works

  1. Identity. Hands the argument straight back.
  2. Constant. Builds a function that will return 10 later.
  3. Types differ. One is the value; the other is a wrapper.
  4. Rule. Need the value now → identity. Need a fixed callback → constant.

Browser & Runtime Support

_.identity 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

_.identity()

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
_.identity 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

_.identity(value) returns the same value you pass in. In math that is f(x) = x. Example: stooge === _.identity(stooge) is true.
var stooge = {name: 'moe'}; stooge === _.identity(stooge) returns true. identity does not copy the object — it returns the original reference.
It looks useless alone, but Underscore uses it as the default iteratee. When a callback is omitted or null, identity is what runs: each item passes through unchanged.
identity returns the same reference. A clone is a new object. stooge === _.identity(stooge) is true; after cloning, that comparison would be false.
identity returns whatever you pass in this call. _.constant(value) returns a function that always yields that fixed value later and ignores later arguments.
No. It is a stable Underscore utility kept around for default iteratees. You can also use it as a truthy filter predicate.

Next: _.constant()

Learn how to turn a value into a reusable “always return this” callback.

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