Lexical Scope

noun

say it: “LEK-sih-kul skohp” /ˈlɛksɪkəl skoʊp/

The rule that a function can see the variables around the place where it was written, not the place where it is called.

What is Lexical Scope in JavaScript?

Lexical Scope — The rule that a function can use names from where it was written.

const taxRate = 0.08;

function addTax(price) {
    const tax = price * taxRate;
    return price + tax;
}

In a sentence

  • “Because of lexical scope, the inner function reads the greeting from the function it's written inside, no matter who calls it.”

Level: Journeyman · More JavaScript terms at this level

Updated