▲ 115 ▼ The JavaScript type coercion algorithm (lemmy.ml) submitted 1 year ago by sleeplessone@lemmy.ml to c/programmerhumor@lemmy.ml 37 comments fedilink hide all child comments
[–] Telemachus93@slrpnk.net 8 points 1 year ago (4 children) It's not. Just tried in my Browser Console: 2 == true // returns false permalink fedilink source parent hideshow 4 child comments replies: [–] retrolasered@feddit.uk 6 points 1 year ago (3 children) 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.. permalink fedilink source parent hideshow 3 child comments replies: [–] Excel@beehaw.org 3 points 1 year ago 2 is not == true, but !!2 is true permalink fedilink source parent [–] Telemachus93@slrpnk.net 3 points 1 year ago (1 child) 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. permalink fedilink source parent hideshow 1 child comment replies: [–] retrolasered@feddit.uk 3 points 1 year ago Yeah its checking for not null with if isnt it. Maybe thats what has me confused permalink fedilink source parent
[–] retrolasered@feddit.uk 6 points 1 year ago (3 children) 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.. permalink fedilink source parent hideshow 3 child comments replies: [–] Excel@beehaw.org 3 points 1 year ago 2 is not == true, but !!2 is true permalink fedilink source parent [–] Telemachus93@slrpnk.net 3 points 1 year ago (1 child) 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. permalink fedilink source parent hideshow 1 child comment replies: [–] retrolasered@feddit.uk 3 points 1 year ago Yeah its checking for not null with if isnt it. Maybe thats what has me confused permalink fedilink source parent
[–] Excel@beehaw.org 3 points 1 year ago 2 is not == true, but !!2 is true permalink fedilink source parent
[–] Telemachus93@slrpnk.net 3 points 1 year ago (1 child) 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. permalink fedilink source parent hideshow 1 child comment replies: [–] retrolasered@feddit.uk 3 points 1 year ago Yeah its checking for not null with if isnt it. Maybe thats what has me confused permalink fedilink source parent
[–] retrolasered@feddit.uk 3 points 1 year ago Yeah its checking for not null with if isnt it. Maybe thats what has me confused permalink fedilink source parent