This exercise
features a “stored function” printNumTwo = function() :
var printNumTwo;
for (var i = 0; i < 3; i++) {
if (i === 2) {
printNumTwo = function() {
return i;
};
}
}
console.log(printNumTwo());
// returns 3
I don’t quite understand what is happening when the loop passes over that function, because I thought nothing would execute after the return i statement.
But I put a console.log("this is " + i) just after the if statement closing bracket (inside the for loop). It logs
this is 0
this is 1
AND it logs
this is 2
So am I right in understanding that the “stored function” is just waiting until the for loop is completely finished to execute? (like recursion)