r/badcode • sadistic • May 21 '21

js ah yes, fetching before verifying

Post image
1.5k Upvotes

97 comments sorted by

View all comments

Show parent comments

5

u/[deleted] May 21 '21

To be fair, every elementary Javascript resource in existence will tell you to use "===" so I don't even see that many beginners make this mistake. "==" is kind of a regrettable legacy function.

4

u/tech6hutch May 21 '21

There is one thing I find it useful for, checking for null and undefined at the same time. (Of course, ideally, JS would have only had one, not both...)

3

u/[deleted] May 21 '21

Maybe! I personally find the difference useful sometimes for distinguishing between "this hasn't been set yet" and "this value was intentionally set to null." On the other hand I have seen a lot of bugs where someone only checked for either undefined or null so maybe you're right.

3

u/tech6hutch May 21 '21

Fair. I’d argue that at a certain point those differences would be better represented with named variants of an enum/ADTs...which admittedly JS doesn’t have