By the end of this tutorial, you’ll know when and why Lodash’s _.identity() returns values unchanged—and how it fits into maps, filters, and composition pipelines.
01
Core Syntax
_.identity(value) returns value.
02
No-Op Iteratee
Pass-through callback for _.map.
03
Truthy Filter
_.filter(arr, _.identity) drops falsy items.
04
Flow Pipelines
Placeholder step in _.flow.
05
vs constant
Pass-through vs fixed return.
06
vs arrow fn
When a named helper reads better.
Fundamentals
What Is _.identity()?
_.identity() is the simplest Lodash util: it takes a value and returns it unchanged. Think of it as a named version of (x) => x—a pass-through or “no-op” transform.
💡
Beginner tip — function vs call
_.identity(42) returns 42. Passing _.identity (without calling it) gives you a function reference—useful as a callback: _.map([1, 2, 3], _.identity).
It looks trivial, but many Lodash methods accept iteratee callbacks. When you need “don’t transform this” without writing an inline arrow, _.identity documents that intent clearly.
Foundation
📝 Syntax
Call it directly or pass the function reference as a callback:
javascript
_.identity(value)
Syntax Rules
value — any value; returned as-is.
Extra arguments — ignored; only the first argument is returned.
As callback — pass _.identity without parentheses to methods like _.map.
Reference equality — objects and arrays are returned by reference, not cloned.
_.map always builds a new array; identity only means each element is copied without transformation. For primitives the values match; for objects the references are shared.
📈 Practical Patterns
Truthy filtering, flow pipelines, and default callbacks.
Example 3 — Filter truthy values
Used as a predicate, identity returns each element; _.filter keeps truthy results.
This is a common functional pattern: identity as predicate keeps truthy values. _.pickBy(obj) without a predicate uses a similar identity-style check on object values.
Example 4 — Pass-through in a flow pipeline
Use identity as the first step when you want to document “input unchanged, then transform.”
The old tutorial incorrectly suggested processValue(value = _.identity) returns data when omitted—it actually assigns the function as the parameter. Default callbacks should be invoked: mapper(item).
Example 6 — identity vs constant
Identity passes input through; constant always returns one fixed value.
Use _.identity when a callback slot must be filled with a no-op
Default mapper parameters to _.identity, then call it
Prefer identity over magic inline arrows in functional Lodash code
Use _.filter(arr, _.identity) for readable truthy filtering
Document pipeline steps with identity when input should pass through
❌ Don’t
Use identity expecting a deep clone of objects
Assign _.identity as a default data value— it is a function
Call _.filter(_.identity) without a collection argument
Swap identity for constant when output must depend on input
Overuse where omitting the iteratee is already clear
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about _.identity()
Use these points when you need a pass-through function.
5
Core concepts
🔀01
Pass-through
Return first arg.
Basics
📊02
Map iteratee
No-op transform.
Practical
🔎03
Filter truthy
Drop falsy items.
Pattern
🔗04
Not constant
Input matters.
Compare
→05
iteratee
Next: shorthands.
Next step
❓ Frequently Asked Questions
_.identity(value) returns the first argument unchanged. When used as a callback (for example _.map(arr, _.identity)), it passes each element through without transforming it.
They behave the same for a single argument. _.identity is a named, reusable function reference—handy when an API expects a function and you want a clear no-op transform.
_.identity returns whatever you pass in. _.constant(fixed) returns the same fixed value every call and ignores all arguments. Use identity for pass-through; use constant for always-return-this-value.
_.filter(collection, _.identity) keeps truthy values and removes falsy ones (0, false, '', null, undefined, NaN). It is a concise alternative to _.compact for arrays or a readable truthy filter.
You can use value = _.identity as a default callback parameter when the caller may omit a transform function—then invoke it as transform(item). Do not use it as a default value for data; it is a function reference, not a placeholder value.
Use it as a no-op iteratee in map/filter/sortBy, as the first or last step in _.flow pipelines, when APIs require a function but you want unchanged values, and anywhere a named pass-through reads clearer than an inline arrow.
Did you know?
In mathematics, an identity function satisfies f(x) = x for all x in its domain. Lodash’s _.identity is that idea in JavaScript— and it is the default iteratee behavior behind several collection methods when you omit a custom callback.