Tell us what’s happening:
I can’t understand why the output is 3 in this challenge. The loop already encountered a return statement the loop should stop and the increment for variable i should not happen? Am I right?? or Am I missing something?
Your code so far
var printNumTwo;
for (var i = 0; i < 3; i++) {
if (i === 2) {
printNumTwo = function() {
return i;
};
}
}
console.log(printNumTwo());
// returns 3
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36
.
Challenge: Compare Scopes of the var and let Keywords
Link to the challenge: