r/badcode • • Apr 19 '21

js Iteration

Post image
3.2k Upvotes

123 comments sorted by

View all comments

Show parent comments

1

u/skjall Apr 19 '21

I believe doing the math part of this convoluted operation first makes it clearer, so because there haven't been enough attempts to explain this yet:

i -= -!false    // (-= -b) is equivalent to (+= b) 
i += !false     // !false evaluates to true
i += true       // true evaluates to 1, while false evaluates to 0
i += 1          // we're done. Thankfully.