Skip to content

Instantly share code, notes, and snippets.

@lspdv
Last active Sep 8, 2017
Embed
What would you like to do?
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