Skip to content

Instantly share code, notes, and snippets.

@pgainda
Created May 7, 2013 19:14
Show Gist options
  • Save pgainda/5535297 to your computer and use it in GitHub Desktop.
Save pgainda/5535297 to your computer and use it in GitHub Desktop.
animals.length will be read only once before our loop starts printing them. This makes our new code a little faster than what we had before.
var i;
var animals = ["cat", "dog", "ferret"];
var length = animals.length;
// Loop goes here
for (i=0;i<length;i++){
console.log(animals[i]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment