I recently got the opportunity to do looping in javascript and I was rather confused whether to use for loop or while statement.
var i = foo.length;
while(i--){
}
or
for(var i=0 ;i<=foo.length;i++){
}
I want to know from javascript guys which one is more effecient to use and under what circumstances should we use them accordingly. Is it same reason as in java or someting different.
In theory the
whileloop is quicker because theforloop looks up thelengthattribute offooevery time though the loop, but in real-world use it’s going to make an immeasurably small difference.