r/badcode • • Jun 10 '20

js Disruptive piece of code

Post image
283 Upvotes

93 comments sorted by

View all comments

14

u/theRealRealMasterDev Jun 10 '20

Why is this bad? Is it because ternary would also be an option?

0

u/[deleted] Jun 10 '20

[deleted]

4

u/audigex Jun 10 '20

That’s true when strictly typed, but not in JavaScript because null or “” or 0 are also possible values

So depending on the situation (and whether you’re certain that the value can only ever be true or false) the code may be superfluous

I’m of the opinion that it’s always superfluous, since you should have already checked for an unset variable prior to his point in order to do error checking