I was convinced that any logical expression in Javascript will return a boolean value, yet this expression returns a number 0 instead of a bool:
0 && true
> 0
Why is that so? How do I approach logical expressions in Javascript in this case to prevent this kind of mistake in the future?
Background story - I was baffled by this statement in jQuery:
$('.something').toggle(0 && true);
It doesn't toggle the element because '0' is returned, and not a boolean!
Maybe there are some clever reasons why this is so, but can't say I like it.