1
function test(params) {
console.log(color);
}
let color = "red";
test();
2
function test(params) {
console.log(color);
}
test();
let color = "red";
1 function seems to be able to 'see'/access color
because the line which invokes the function can see color
. When the line that invokes the function is above color
(like in 2) the only way color
is seen is if it is 'above' or inside the function some way.
Is it fair for me to deduce this rule:
FunctionA can access a (non-global) variable that exists outside functionA when it is seen by the line that invokes functionA?
Please don't comment linking to a big document about closures. I'm talking about a specific situation.