Last active
January 21, 2018 19:24
-
-
Save ifkas/daa9dda199ff059f85ee2a6bc49f6dfe to your computer and use it in GitHub Desktop.
ES6 for loop with closure
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
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