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

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jquery - Keeping Kendo Datepicker in min/max range -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -