Skip to main content

eq()

eq(value, other): boolean

Performs a SameValueZero comparison between two values to determine if they are equivalent.

DEPRECATED

Use Object.is() or === directly instead.


Parametersโ€‹

value: unknownโ€‹

The value to compare.

other: unknownโ€‹

The other value to compare.


Returns: booleanโ€‹

true if the values are equivalent, else false.


See Alsoโ€‹


Sinceโ€‹

2.0.0


Also known asโ€‹

eq (Lodash) ยท equals (Ramda, Effect) ยท โŒ (es-toolkit, Remeda, Radashi, Modern Dash, Antfu)


Exampleโ€‹

// โŒ Deprecated approach
eq(1, 1); // => true
eq('a', 'a'); // => true
eq(NaN, NaN); // => true

// โœ… Recommended approach
Object.is(1, 1); // => true
Object.is('a', 'a'); // => true
Object.is(NaN, NaN); // => true (unlike ===)

// Or simply use === for most cases
1 === 1; // => true
'a' === 'a'; // => true

How it works?โ€‹

Performs SameValueZero comparison between two values. Deprecated: Use === or Object.is() directly.

Native Equivalentโ€‹

// โŒ eq(a, b)
// โœ… a === b
// โœ… Object.is(a, b) // for NaN handling

Use Casesโ€‹

Compare values ๐Ÿ“Œโ€‹

Strict equality comparison.

a === b;

Check identityโ€‹

Check if two values are identical.

const obj = { id: 1 };
const ref = obj;
obj === ref; // true