You Don't Know JS and watch
What is Scope?
- The ability to store values and pull values out of variables is what gives a program state.
- But, where do those variables live?, where are they stored?, and how does our program find them when it need them?
- set of rules for storing variables : Scope
- Engine: responsible for start-to-finish compilation and execution.
- Compiler: handles parsing and code-generation.
- Scope: collects and maintains a look-up list of all the declared identifiers.
how it works?
two distinct actions are taken for a variable assignment
- Compiler declares a variable (if not previously declared in the current scope)
- when executing, Engine looks up the variable in Scope and assigns to it, if found.