Skip to content

Instantly share code, notes, and snippets.

@alexshelkov
Created February 3, 2022 15:50
Show Gist options
  • Save alexshelkov/1449943c65aea361a200a4a160ae8840 to your computer and use it in GitHub Desktop.
Save alexshelkov/1449943c65aea361a200a4a160ae8840 to your computer and use it in GitHub Desktop.
var i1 = 0;
while (i1 < 3) {
let i = i1; // 'i' is a block scoped variable,
// each code block have unique copy of it
setTimeout(() => { // timeout callback
console.log(i, i1);
}, i * 1000);
i1++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment