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