JSFiddle - React, Tailwind, and code Playground

JavaScript

console.clear();
var funcs = {};
for (var i = 0; i < 3; i++) {          
    // let's create 3 functions
    funcs[i] = new function() {   
        // and store them in funcs
        var closedVariable = i;
        return function(){
            console.log("My value: " + closedVariable); 
            // each should log its value.
        };
    };
}
for (var j = 0; j < 3; j++) {
    funcs[j]();                        
    // and now let's run each one to see
}