Why? I understand that in javascript boolean expressions 0 casts to
false and 1 casts to true.
Because Number(true)
=> 1
As per spec of abstract equality expression evaluation
- If Type(x) is Boolean, return the result of the comparison ToNumber(x) == y.
Hence a
is first coerced into a Number and then compared with 1.