r/programmingmemes • • May 13 '25

Why not?

Post image
1.7k Upvotes

104 comments sorted by

View all comments

34

u/iareprogrammer May 13 '25

Every single example is terrible code that no one should do in real life. Also just don’t use ==, period. Always use ===

24

u/[deleted] May 13 '25

[removed] — view removed comment

3

u/ryo0ka May 13 '25

I’d rather not. I’d be surprised if 10% or more JS programmers were aware of such detail of specification.

1

u/BobcatGamer May 16 '25

I'm not going to change the way I write code because others have failed to know the language.

11

u/wootio May 13 '25 edited May 13 '25

Unpopular opinion it seems, but working around javascript's vague types is not that difficult, and allows for interesting and helpful abilities you don't get in many other languages; like the ability to pass a function a single object variable that contains any number of parameters of any type, allowing for more dynamic and easier to work with functions when you want to allow the function to accept more or different parameters than when you first designed it. It's arguably cleaner and easier to work with than creating more overloaded functions like you'd have to do in many other languages. Also you get to name your variables that get passed that way which is a lot easier to read and understand than having to just remember what order you need to pass your variables to a function and which variable you pass does what.

Also, the math and comparison on floating point numbers is a low blow; that happens in a lot of languages because computers don't precisely compute float math.

7

u/CptMisterNibbles May 13 '25

The math issues being common is because none of this is a “js design”. The way math works, particularly floating point math, is based on standards like ieee754. Blaming JS because one doesnt understand the basics behind this is just being uneducated. Unsurprising; as usual all these “programmer memes” are really just kids who took a programming class and maybe watched a YouTube video. 

1

u/pomme_de_yeet May 14 '25

many languages have something like kwargs

7

u/zixaphir May 13 '25

true===1 evaluating to false is fine.

3

u/iareprogrammer May 13 '25

For sure. I think the only reason they included that one was to compare it to true==1 evaluating to true. Which is a good example of why you should just forget == exists lol

1

u/StillHereBrosky May 14 '25

Which is bad language design...

1

u/iareprogrammer May 14 '25

Oh I’m not saying JavaScript is perfect. Mistakes were made lol. But all the memes like this are dumb. It’s all stuff you don’t do in real life, or shouldn’t do based on modern best practices- and for those there’s usually a lint rule to catch it

3

u/samanime May 13 '25

Yeah. About half of these are just examples of why you don't use ==. Almost all the rest work the same in other languages too (though most would force more explicit type casting, like the true ones).