JSFiddle - React, Tailwind, and code Playground

HTML

<div>Output will appear below when you click 'Run':</div>
<br/>

JavaScript

function factory(when){
	return function(){
		return when;
    }
}

var f = factory(0);
var g = factory(1);


// these all work correctly...
$('body').append('<div>**Values from your original tests:**</div>');
$('body').append('<div>' + (f === g) + '</div>');
$('body').append('<div>' + (f()) + '</div>');
$('body').append('<div>' + (g()) + '</div>');
//


$('body').append('<br/><br/>');
var myArr = [];


//It will even execute with the correct value when looping...
$('body').append('<div>**Values from the loop:**</div>');
for(var i=0; i<25; i++) {
    $('body').append('<div>' + factory(i)() + '</div>');
    
    //or I can push them on an array to be executed later...
    myArr.push(factory(i)());
}


//no print out the values from the array...
$('body').append('<div>**Values from the array:**</div>');
for(var j=0; j<25; j++) {
    $('body').append('<div>' + myArr[j] + '</div>');
}