Skip to content

Instantly share code, notes, and snippets.

@solominh
Created January 23, 2017 19:44
Show Gist options
  • Select an option

  • Save solominh/afe06ebaa41e682e8159909e46a2ccc4 to your computer and use it in GitHub Desktop.

Select an option

Save solominh/afe06ebaa41e682e8159909e46a2ccc4 to your computer and use it in GitHub Desktop.
// Fail var
for (var i = 1; i <= 3; i++) {
console.log('forloop', i)
Promise.resolve().then(() => {
console.log(i); // Always log 5
})
}
// Use let instead
for (let i = 1; i <= 3; i++) {
console.log('forloop', i)
Promise.resolve().then(() => {
console.log(i); // Always log 5
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment