Last active
December 30, 2015 21:50
-
-
Save gnab/7889490 to your computer and use it in GitHub Desktop.
Block binding.
This file contains 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 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