

8·
4 days agoIt’s not. Just tried in my Browser Console:
2 == true // returns false
It’s not. Just tried in my Browser Console:
2 == true // returns false
Mh, ‘0’ is a nonempty string, so !‘0’ returns false. Then of course !(!‘0’) would return true. I’d absolutely expect this, Python does the same.
And the second thing is just JavaScript’s type coercion shenanigans. In Python
bool('0') # returns True because of nonempty string
bool(int('0')) # returns False because 0 == False
Knowing that JavaScript does a lot of implicit type conversions, stuff like that doesn’t strike me as very surprising.
In other languages that shouldn’t be equal either though, right?
Maybe you meant
if (2){ console.log("nonzero ints are truthy") } else { console.log("no they're not") }
Which would output
nonzero ints are truthy
and that would actually work in all languages I know. But that’s different from being equal.