this post was submitted on 05 Aug 2025
122 points (98.4% liked)

Programmer Humor

37634 readers
669 users here now

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

Rules:

founded 6 years ago
MODERATORS
 

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 3 days ago (3 children)

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

[–] Midnitte@beehaw.org 7 points 3 days ago* (last edited 3 days ago)

3 - 1 // -> 2

3 + 1 // -> 4

'3' - 1 // -> 2

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

[–] Telemachus93@slrpnk.net 8 points 3 days ago (1 children)

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

2 == true // returns false
[–] retrolasered@feddit.uk 6 points 3 days ago (2 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..

[–] Excel@beehaw.org 3 points 2 days ago

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

[–] Telemachus93@slrpnk.net 3 points 2 days ago (1 children)

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 2 days ago

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

[–] NewDark@hexbear.net 5 points 3 days ago

2 is 'truthy', or rather, not 'falsy'.

I'm not even kidding.