javascript - Omitting Condition in For Loop -
Let anyone help me understand why the following code works:
Var someNumbers = [1,2,3,4,5]; Var length = some Numbers.length; (Var i = length; i--;) {console.log (i); } How is this once the i equation considered for 0 for the loop? What about negative numbers? Will not this cause an infinite loop?
In javascript, anything can be a condition! In this situation, it is i - . Once i - returns 0 the loop will close because 0 is Farsi. The part that is missing is the third expression (see "last expression", see for loop) where you usually get increment / decreasing operation, but this case In both the "conditions" are combined in the expression.
Comments
Post a Comment