JSFiddle - React, Tailwind, and code Playground

by Ian Oxley

JavaScript

// Loop closure with additional closure
for (var i = 0; i < 10; i++) {
    console.log('no callback: ' + i);
    var current = i;
    (function(x) {        
        setTimeout(function() {
            console.log('with callback: ' + x);
        }, 5000);
    })(current);
}