> For the complete documentation index, see [llms.txt](https://bryan-guner.gitbook.io/my-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bryan-guner.gitbook.io/my-docs/job-search/interview-prep/interview-questions./what-is-the-difference-between-lexical-scoping-and-dynamic-scoping.md).

# What is the difference between lexical scoping and dynamic scoping?

## Answer

Lexical scoping refers to when the location of a function's definition determines which variables you have access to. On the other hand, dynamic scoping uses the location of the function's invocation to determine which variables are available.

## Good to hear

* Lexical scoping is also known as static scoping.
* Lexical scoping in JavaScript allows for the concept of closures.
* Most languages use lexical scoping because it tends to promote source code that is more easily understood.

### Additional links

* [Mozilla Docs - Closures & Lexical Scoping](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures)
