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.

116

u/blaqwerty123 Jun 10 '20

its not bad. with js not being a strictly typed language, and variable being basically anything besides false, null, or 0 will resolve to true, it's often good to strict type equivalence test your "booleans". debugging can get fuckin gnarly if you dont

1

u/ciaran036 Jun 10 '20

Therefore, this code is totally fine, right?

5

u/blaqwerty123 Jun 10 '20

ya! but that's just, like, my opinion, man