What values of someOtherVar
will cause someVar
to be true
?
Only null
and undefined
.
The algorithm in the spec is relatively straight forward:
- If
Type(x)
is the same as Type(y)
, then Return the result of performing Strict Equality Comparison x === y
.
- If
x
is null and y
is undefined, return true.
- If
x
is undefined and y
is null, return true.
- If
Type(x)
is Number and Type(y)
is String, return the result of the comparison x == ToNumber(y)
.
- If
Type(x)
is String and Type(y)
is Number, return the result of the comparison ToNumber(x) == y
.
- If
Type(x)
is Boolean, return the result of the comparison ToNumber(x) == y
.
- If
Type(y)
is Boolean, return the result of the comparison x == ToNumber(y)
.
- If
Type(x)
is either String, Number, or Symbol and Type(y)
is Object, return the result of the comparison x == ToPrimitive(y)
.
- If
Type(x)
is Object and Type(y)
is either String, Number, or Symbol, return the result of the comparison ToPrimitive(x) == y
.
- Return false.
Step 1 handles the case null == null
. Step 2 and 3 handle the cases null == undefined
and undefined == null
. Step 6 and 7 handle the cases where the other value is a boolean, so then you end up comparing a number against null
. Since null
is not an object, number, string, boolean or symbol, non of the other steps apply, so false
is returned (step 10).
What coerces from a null compare in JavaScript?
Only if the other value is a boolean it would be coerced to a number, so you end up comparing either 0 == null
or 1 == null
, both of which are false
.
In all other case, no type coercion is happening (nothing is coerced to null
and null
is not coerced to any other data type).