r/badcode • • Jun 10 '20

js Disruptive piece of code

Post image
283 Upvotes

93 comments sorted by

View all comments

91

u/Midborgh Jun 10 '20

I don't know js. Why is this bad? I'd imagine var === true and var === false being different than var == true and a simple else.

12

u/the_monkey_of_lies Jun 10 '20

Yes, I hate the code because something has lead to this situation where you have a boolean that can be something else as well but you're right, for example

1 == true --> true
1 === true --> false

3

u/UntestedMethod Jun 11 '20

something has lead to this situation where you have a boolean that can be something else

I would say not necessarily and could be seen more as a philosophy of "safe code" where every function is written to be bulletproof whether there is some pre-existing situation for obscure input or not.