JavaScript · Junior · Question 8 of 75
How does == differ from ===?
- ✓Correct answer:
==coerces types before comparing,===compares without coercion - 2
===coerces types before comparing, while==compares without coercion - 3
==compares only numbers, while===compares values of any type
Explanation
0 == '' and '1' == 1 are true because of coercion, but false with ===. Loose equality rules are confusing, so === is almost always used. A handy exception: x == null checks for both null and undefined at once.