Skip to content

Instantly share code, notes, and snippets.

@lspdv
Last active September 8, 2017 10:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lspdv/be7e57bd8deea775dd2cf0b13c880f3a to your computer and use it in GitHub Desktop.
Save lspdv/be7e57bd8deea775dd2cf0b13c880f3a to your computer and use it in GitHub Desktop.
How would you change the second line in the following example so that it prints numbers 0, 1, 2, 3 in this order
//How would you change the second line in the following example so that it prints numbers 0, 1, 2, 3 in this order?
//Please answer fill only to the registration form for MSD Code Academy :-)
for (var i = 0; i < 4; i++) {
setTimeout(() => console.log(i), 0)
}
//A: By changing line 2) ... (function(number) { setTimeout(() => console.log(number), 0)})(i)
//B: By changing line 1) ... for (let i = 0; i < 4; i++) {
//C: By changing line 2) ... var temp = i; setTimeout(() => console.log(temp), 0)
//D: By changing line 2) ... setTimeout((i) => console.log(i), 0)
//E: Have no idea
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment