Sleepless One@lemmy.ml to Programmer Humor@lemmy.mlEnglish · 3 days agoThe JavaScript type coercion algorithmlemmy.mlimagemessage-square44fedilinkarrow-up1122arrow-down12file-text
arrow-up1120arrow-down1imageThe JavaScript type coercion algorithmlemmy.mlSleepless One@lemmy.ml to Programmer Humor@lemmy.mlEnglish · 3 days agomessage-square44fedilinkfile-text
minus-squareTelemachus93@slrpnk.netlinkfedilinkarrow-up8·3 days agoIt’s not. Just tried in my Browser Console: 2 == true // returns false
minus-squareretrolasered@feddit.uklinkfedilinkEnglisharrow-up6·3 days agoI genuinely wasn’t aware of that. I must be getting javascript confused for almost any other language. I wonder how many times ive !!'d a value to make that work without actually absorbing that into my head now…
minus-squareTelemachus93@slrpnk.netlinkfedilinkarrow-up3·3 days agoIn 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.
minus-squareretrolasered@feddit.uklinkfedilinkEnglisharrow-up2·2 days agoYeah its checking for not null with if isnt it. Maybe thats what has me confused
It’s not. Just tried in my Browser Console:
2 == true // returns false
I genuinely wasn’t aware of that. I must be getting javascript confused for almost any other language. I wonder how many times ive !!'d a value to make that work without actually absorbing that into my head now…
2 is not == true, but !!2 is true
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.
Yeah its checking for not null with if isnt it. Maybe thats what has me confused