118

That's it. That's the meme.

you are viewing a single comment's thread
view the rest of the comments
[-] retrolasered@feddit.uk 3 points 4 days ago

But then why 2 == true if true is converted to 1

[-] Midnitte@beehaw.org 8 points 4 days ago* (last edited 4 days ago)

3 - 1 // -> 2

3 + 1 // -> 4

'3' - 1 // -> 2

'3' + 1 // -> '31'

[-] Telemachus93@slrpnk.net 8 points 4 days ago

It's not. Just tried in my Browser Console:

2 == true // returns false
[-] retrolasered@feddit.uk 6 points 4 days ago

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..

[-] Excel@beehaw.org 3 points 4 days ago

2 is not == true, but !!2 is true

[-] Telemachus93@slrpnk.net 3 points 4 days ago

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.

[-] retrolasered@feddit.uk 2 points 3 days ago

Yeah its checking for not null with if isnt it. Maybe thats what has me confused

this post was submitted on 05 Aug 2025
118 points (100.0% liked)

Programmer Humor

37656 readers
165 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 6 years ago
MODERATORS