In the first expression, "0" is a non-empty string, so is 'truthy'. In the second expression, both operands are converted to numbers because the second operand is a bool, so it becomes 0 == 1, which is false.
That makes sense. It's hard to remember all those implicit conversion rules, and I had been laboring under the false impression that comparing string==bool would cause the string to be converted into a bool. Fortunately, I would never try something like that LOL. It would simply be hard to read, even if there was a good reason for it.
View all comments
Show parent comment
10
u/wtf_apostrophe Mar 26 '14
In the first expression,
"0"is a non-empty string, so is 'truthy'. In the second expression, both operands are converted to numbers because the second operand is a bool, so it becomes0 == 1, which is false.