r/javascript • • Mar 09 '15

Things every JavaScript developer should know

http://ilikekillnerds.com/2015/03/things-every-javascript-developer-should-know/
326 Upvotes

118 comments sorted by

View all comments

1

u/back-stabbath Mar 10 '15

I'm not quite understanding

while (i--){ ..... }

So when i equals zero, the loop breaks because 0 is sort of equal to false? Is this a safe solution?

1

u/ambalbemuth Mar 10 '15

As long as i isn't modified anywhere else and starts being an integer > 0, why wouldn't it?

1

u/kyrul Mar 10 '15

I think the only way it'd be unsafe is if multiple things were modifying i, such that it could decrement to a negative number in the span of the loop