JavaScriptQuestion 15 of 36
Do you know about lexical scope?
Answer out loud or in your head first, then compare.
Answer
Lexical scope means that access to variables depends on where the function was defined, not where it's called.
JavaScript
const name = "global";
function outer() {
const name = "outer";
return function inner() {
console.log(name);
};
}
const fn = outer();
fn();output:
outerLexical scope is what makes closures possible.
How did it go? Be honest — “Not yet” puts the question on your review list.