For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/function/identity.md.

identity es-toolkit

Returns the input value as is.

const result = identity(value);

Usage

identity(value)

Use identity when you want to return a value without modifying it.

This is useful as a default value for functions passed as arguments. It's commonly used to return the value itself in array map or filter operations, or as a placeholder in functional programming.

import { identity } from 'es-toolkit/function';

// Returns the number as is
const num = identity(5);
console.log(num); // 5

// Returns the string as is
const str = identity('hello');
console.log(str); // 'hello'

// Returns the object as is
const obj = identity({ key: 'value' });
console.log(obj); // { key: 'value' }

// Example using with an array
const numbers = [1, 2, 3, 4, 5];
const same = numbers.map(identity);
console.log(same); // [1, 2, 3, 4, 5]

Parameters

valueTrequired

The value to return.

Returns

Returns the input value as is.

T
Source: es-toolkit

Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.