Equality (==)
Compares two values for equality after type coercion.
Syntax
a == b
a != b
Returns
boolean — `true` if the operands are equal after type coercion.
Examples
console.log(1 == "1");
console.log(0 == false);
Output
true
true
console.log(null == undefined);
console.log(null == 0);
Output
true
false
console.log(NaN == NaN);
Output
false
Notes
- Performs type coercion, which leads to surprising results; prefer
strict equality (`===`).
- `null == undefined` is `true`, but neither equals `0` or `""`.
- `NaN` is never equal to anything, including itself.
Browser & runtime support
| Environment | Since version |
|---|---|
| chrome | 1.0 |
| firefox | 1.0 |
| safari | 1.0 |
| edge | 12 |
| node | 0.10 |