javascript - Conditional statement in a for loop simple as i -


i found these lines of code in library made listen touch events :

  ( var = elements.length; i; i-- ) {     iterator( elements[ - 1 ], elements );   } 

it surprised me second. understand code way : integer positive or null , conditional statement if positive.
understand right ? return false when i==-1 ? or did miss (like it's possible write loop without conditional statement) ?

the conditional if( i) proceedtonextiteration();

as numbers go, 0 falsy , fail check. -1 true in above condition.

for reason, i'd rewrite code as:

for( var = elements.length-1; >= 0; i--) {     iterator( elements[i], elements); } 

it's more explicit final condition.


Comments

Popular posts from this blog

rdbms - what exactly the undo information lives in oracle? -

bash - How do you programmatically add a bats test? -

java - Getting exception in JDBC thin driver -