For a function, does it get the variable scope during the declaration, or before the run time?
I tried the first part of code below and it doesn't work. The second part works. Can somebody shed some insight on the difference?
//// does not work
function a() {
console.log(v1);
}
function b() {
let v1 = 1;
a();
}
b();
//// does work
function a() {
console.log(v1);
}
function b() {
a();
}
let v1 = 1;
b();