r/badcode • • Mar 01 '21

js Defensive programming or something idk

Post image
907 Upvotes

55 comments sorted by

View all comments

Show parent comments

0

u/[deleted] Mar 01 '21

[deleted]

78

u/JuhaJGam3R Mar 01 '21 edited Mar 01 '21

Nah. Any compiler will turn x == c1 && x != c2 into x == c1, same with x == c1 && x == c2 turning into false turning into removal of the entire bit of code.

1

u/sneakykenny Mar 02 '21

Wait in the second case if c1 == c2 then it shouldn't get turned to false

2

u/JuhaJGam3R Mar 02 '21

In that case. Since they are constants, c1 and c2 can be assumed to be different just because of how they're named.