Loading…
A short voice session: one question, one follow-up, then instant feedback — up to 5 minutes.
JavaScript uses lexical scope: a function looks through the scopes where it was defined. It cannot directly read another unrelated function's local variables.
A name is looked up first in the current scope, then in enclosing lexical scopes. An inner variable with the same name shadows an outer variable. function first() { const secret = 3; } does not make secret visible inside an unrelated function second(). Where a function is called does not change the lexical scopes in which its ordinary variable names are resolved.