Closure Example

How closures and captures work

by Jeremy Likness

JavaScript

function makeTimeout(x) {
    setTimeout(function () {
        console.log(x);
    }, 0);
}

for (x = 0; x < 10; x += 1) {
    makeTimeout(x);
}