JSFiddle - React, Tailwind, and code Playground

JavaScript

var url;
//wrong: because of variable hoisting the value of x is 9 at the time it's evaluated
for (x = 0; x < 10; x++) {
    url = 'http://capc-pace.phac-aspc.gc.ca/details-eng.php?project=' + x;
    setTimeout(function () {
        console.log(url);
    }, 1);
}

//correct behavior: by passing the url as the parameter to a function you are creating a new 'scope' and the value does not get overwritten
for (x = 0; x < 10; x++) {
    url = 'http://capc-pace.phac-aspc.gc.ca/details-eng.php?project=' + x;
    (function (ownScope) { 
        setTimeout(function () {
            console.log(ownScope);
        }, 1);
    }(url));
}