Skip to content

Instantly share code, notes, and snippets.

@cho45
Created June 9, 2016 07:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cho45/f867d117dd2c7756290f19781183c413 to your computer and use it in GitHub Desktop.
Save cho45/f867d117dd2c7756290f19781183c413 to your computer and use it in GitHub Desktop.
for of vs for
<script>
var array = [];
for (var i = 0; i < 1000; i++) {
array[i] = i;
}
</script>
var sum = 0;
for (var i = 0, len = array.length; i < len; i++) {
sum += array[i];
}
var sum = 0;
for (var x of array) {
sum += x;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment