Skip to content

Instantly share code, notes, and snippets.

@gnab
Last active December 30, 2015 21:50
Show Gist options
  • Save gnab/7889490 to your computer and use it in GitHub Desktop.
Save gnab/7889490 to your computer and use it in GitHub Desktop.
Block binding.
var nums = [1, 2, 3];
for (var i in nums) {
setTimeout(() => {
console.log('var i =', nums[i]);
}, 1000 * i);
}
for (let i in nums) {
setTimeout(() => {
console.log('let i =', nums[i]);
}, 1000 * i);
}
// =>
// var i = 3
// let i = 1
// var i = 3
// let i = 2
// var i = 3
// let i = 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment