lexical scope

noun
UK /ˈlɛksɪkəl skəʊp/
US /ˈlɛksɪkəl skoʊp/

Lexical scope is a rule that says a piece of code can see the names made around it where it was written.

Because of lexical scope, the inner function can use the variable defined in the outer function.


OTHER MEANINGS

2. The region of a program where a name is visible based on where it is written in the source code.

The variable's lexical scope ends at the closing brace of the function.

3. A way to decide which variable a name refers to by looking at the text of the program, not at runtime.

Lexical scope makes it easy to tell which x is used just by reading the code.

4. The set of declarations that are in effect at a particular point in the source text.

Inside the loop, the lexical scope includes the loop counter and any outer variables.