CodePark/ questions / Types & coercion
START PRACTICINGPRACTICE
Frontend question · JavaScript › Types & coercion

What does this log?

console.log(null == 0, null >= 0, undefined == null, undefined == 0);
false true true false

Loose equality (==) has a special rule for null and undefined. They are equal to each other and to nothing else. So null == 0 and undefined == 0 are both false, and undefined == null is true.

Comparison operators like
>= follow a different rule. They convert both sides to numbers. null becomes 0, so null >= 0 becomes 0 >= 0, which is true.

The tempting option "false false true false" is wrong because it assumes
>= uses the same rule as ==. It does not.