Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
javascript: function defined inside a loop
var numbers = [1,2,3];
for (var i = 0, n = numbers.length; i<n; i++) {
var num = numbers[i];
setTimeout(function() {
console.log(num);
}, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.