Skip to content

Instantly share code, notes, and snippets.

@camilomontoyau
Created September 3, 2019 19:36
Show Gist options
  • Save camilomontoyau/e2bb6180936a1894aca9dcf1c399297c to your computer and use it in GitHub Desktop.
Save camilomontoyau/e2bb6180936a1894aca9dcf1c399297c to your computer and use it in GitHub Desktop.
scope.js
/* for (var i = 1; i <= 5; i++) {
(function() {
setTimeout(function timer() {
console.log(i);
}, i * 1000);
})();
} */
/* for (var i = 1; i <= 5; i++) {
(function() {
var j = i;
setTimeout(function timer() {
console.log(j);
}, i * 1000);
})();
} */
for (let i = 1; i <= 5; i++) {
(function() {
setTimeout(function timer() {
console.log(i);
}, i * 1000);
})();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment