Hint
Scope is determined where code is written, not where it is called
Lexical scope (static scope) means a function's scope is determined by where it is written in the code — at author time — not by where it is called at runtime.
const x = 'global';
function outer() {
const x = 'outer-fn';
function inner() {
console.log(x); // 'outer-fn' — closes over WHERE inner is DEFINED
}
return inner;
}
const fn = outer();
fn(); // logs 'outer-fn', NOT 'global'
// Even though fn() is called at global level, it remembers outer-fn's scope
This is what makes closures possible — a function carries its scope from where it was created, not from where it's invoked.