I came across this example in a Toptal youtube video that uses syntax that won't run in Chrome, unless I am missing something. This example comes up here (JavaScript closure inside loops – simple practical example) and the same syntax is used. Why is this not running for me/does the indicated line below contain valid syntax?
var x, y, funcs = [];
for(x=0; x<5; x++){
(function(){
var r = x;
funcs.push(function(){
console.log(r);
});
});
};
for (var y=0; y<5; y++){
funcs[y](); //<< is this valid JS syntax/why is it not working for me?
};