2 ms·
> Boolean([]) true > []==false true > [] == ![] true How the hell does that work? Aren't all non-booleans implicitly cast? edit: rephrased
by sesqu 16y ago
> Boolean([])
true
> []==false
true
> [] == ![]
true
How the hell does that work? Aren't all non-booleans implicitly cast?
edit: rephrased
- chc 16y agoIt's because the == operator converts its arguments to be of the same type, and it does so in a rather unintuitive way. This makes it both inefficient and frequently baffling. You pretty much always want === instead, which does not allow comparisons between different types.