Skip to content

Instantly share code, notes, and snippets.

@getify
Last active December 15, 2015 07:39
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 getify/5225304 to your computer and use it in GitHub Desktop.
Save getify/5225304 to your computer and use it in GitHub Desktop.
let in for-loops... not working "as expected"?
for (let i=0; i<5; i++) {
setTimeout(function(){
console.log(i);
},i*1000);
}
// expect:
// 0
// 1
// 2
// 3
// 4
// gets:
// 5
// 5
// 5
// 5
// 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment