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