Skip to content

Instantly share code, notes, and snippets.

Created May 30, 2011 02:39
Show Gist options
  • Save anonymous/998387 to your computer and use it in GitHub Desktop.
Save anonymous/998387 to your computer and use it in GitHub Desktop.
var toLoop = new Array(1000);
 
for (var i = 0; i < toLoop.length; i++) {
    // BAD - the length has to be evaluated 1000 times
}
 
for (var i = 0, len = toLoop.length; i < len; i++) {
    // GOOD - the length is only looked up once and then cached
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment