Created
November 17, 2011 23:02
-
-
Save emkay/1374853 to your computer and use it in GitHub Desktop.
For Loops
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var a = ['cat', 'dog', 'pig', 'bird']; | |
| // works, but you are accessing the a.length property every time. | |
| for (var i = 0; i < a.length; i += 1) { | |
| console.log(a[i]); | |
| } | |
| // better because it is caching length, especially for DOM collections | |
| for (var i = 0, len = a.length; i < len; i += 1) { | |
| console.log(a[i]); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment