Skip to content

Instantly share code, notes, and snippets.

@devarajchidambaram
Created October 4, 2018 12:02
Show Gist options
  • Save devarajchidambaram/6bea371f3e70e4f26073debccb1f19aa to your computer and use it in GitHub Desktop.
Save devarajchidambaram/6bea371f3e70e4f26073debccb1f19aa to your computer and use it in GitHub Desktop.
closure
const arr = [10, 12, 15, 21];
for (var i = 0; i < arr.length; i++) {
(function(i){
setTimeout(function() {
console.log('The index of this number is: ' + i);
}, 3000);
})(i)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment