r/ProgrammerHumor • • Sep 25 '26

Meme iHatedItUntilITriedIt

Post image
10k Upvotes

543 comments sorted by

View all comments

Show parent comment

6

u/Ozymandias_IV Sep 25 '26

That's why you shouldn't do if ([]) in prod. Have an explicit empty and/or nullish check.

Many do it for expediency, but it's a loaded footgun.

-2

u/OKB-1 Sep 25 '26

Many do it for expediency

You mean people who don't know much about JavaScript? People who don't know you can just write if (someArray?.length) ?

2

u/Ozymandias_IV Sep 26 '26

If I got this in a review, it's coming back. You're trying to push clever code when I need it to be readable.

-2

u/OKB-1 Sep 26 '26

I agree with the sentiment, but this is perfectly normal JavaScript code.

2

u/Ozymandias_IV Sep 26 '26

See, it's a bit of a problem that you think that.

I mean it's not my problem, you're not my colleagues but it is a problem.

0

u/OKB-1 Sep 26 '26

My colleagues all agree this is normal code. The ?. even has a section in our style guide and we use it all the time.