#
identity
Function • Returns its argument.
identity value → value
Arguments
| name | type | description |
|---|---|---|
| value | Any | Any JavaScript value. |
Returns
| name | type | description |
|---|---|---|
| value | Any | The unaltered argument value. |
#
Description
Named for the mathematical concept of identity. identity returns the first argument you provide it, unaltered. This is the functional version of a no operation. Use it as a default, a fallback, or even just as a placeholder for in-progress code.
Point of Interest
The return value is the arugment value. That is, even when passing an object to identity, the return value is strictly equal to the argument value.
#
Examples
#
Returns its argument.
assert.equal 1,
_.identity 1
assert.equal(1,
_.identity(1));
#
Returns only its first argument.
assert.equal 1,
_.identity 1, 2, 3
assert.equal(1,
_.identity(1, 2, 3));
#
Returns the exact argument. Even objects are strictly equal.
a = company: "Delos"
assert.equal a,
_.identity a
const a = { company: "Delos" };
assert.equal(a,
_.identity(a));