Skip to content

Instantly share code, notes, and snippets.

@ifkas
Last active January 21, 2018 19:24
Show Gist options
  • Save ifkas/daa9dda199ff059f85ee2a6bc49f6dfe to your computer and use it in GitHub Desktop.
Save ifkas/daa9dda199ff059f85ee2a6bc49f6dfe to your computer and use it in GitHub Desktop.
ES6 for loop with closure
for (let i = 0; i<=3; i++) {
setTimeout(function(){
console.log("I have: " + i + "apples");
}, i*2000);
}
// > I have: 1 apples
// > I have: 2 apples
// > I have: 3 apples
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment