this is an example of ES6 Challenge 1 in JS tutorial.
let printNumTwo;
for (let i = 0; i < 3; i++) {
if (i === 2) {
printNumTwo = function() {
return i;
};
}
}
console.log(printNumTwo()); // why this is 2?
console.log(i); // i understood why this is undefined
i don’t understand why 'console.log(printNumTwo()); ’ is 2.
and…
is let declaration in the block statements not hoisted and not on the list of global context??.
and…
when for ?? or if?? statement is run, does JS create a new (local?) context?
sorry my poor question …
haha i’d better learn harder for better questions.
thanks for everybody !