Could someone please explain (or point me to a rule) why the following code doesn’t work
if (true) {
const zz = 20;
somefunc();
}
function somefunc() {
console.log(zz); // Uncaught ReferenceError: zz is not defined
}
However this one does
const zz = 20;
somefunc();
function somefunc() {
console.log(zz); // 20
}
Does the engine skip all if statements when looking for global variables?
I’m not sure I understand why the code doesn’t work exactly and can’t find the exact information for this case.