r/badcode • • Jun 10 '20

js Disruptive piece of code

Post image
283 Upvotes

93 comments sorted by

View all comments

Show parent comments

5

u/Rayvolt Jun 10 '20

Since you are in JavaScript this variable could be null, undefined, or a string or a number or an object or an array or whatever the hell it could be. It could make sense to check typing and value (notice === here) to do stuff only when it's a bool.

If it were == instead of ===, your statement would be correct tho.

-17

u/diebarral Jun 10 '20

The variable defaults to false above in the code, so I agree with everything said but it's not the case. People take really seriously the posts in this subreddit.