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

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -