function fn() {
console.log(foo);
}
const foo = 3;
run();
How come this variable inside of a function can read a global variable that is even declared and assigned under the function statement?
How does JavaScript work in this scenario? I'd like to understand how it works.
fn();
function fn() {
console.log("hello");
}
I know this does work because of function hoisting. But the first code is another story, right?