Scope:

Js is static scoped, also known as lexical scoped, meaning that the scope is created at definition time, not at runtime. Definition: the area or set in which variables and functions can be accessed effectively 3. A scope is a du Lili space used to protect variables from leakage and also play a role in isolation 4. Scopes include global scope, function scope and block-level scope. Global scope: 1. Local scopes are accessible both inside and outside a function: 1. Only inside a function 2. Note that var or let declarations must be used inside functions, except that global variable 3 is called. The function content definition variable has the same name as the function global variable and overwrites the block-level scope: ES6 proposes that let and const functions also have block-level scopeCopy the code

Scope chain:

1. Represents a set of variables that a scope can access. The function, as an object, has a [[scope]] attribute to represent the set 2. Activity variables (AO), object (VO), the execution context = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 1. The current context looks for the required variable, if not, the parent context will look until the window, if not found, error 2 will be reported. The internal environment can access the property methods of the external environment through the scope chain, but the external environment cannot access the properties and methods inside the function. The external environment can only extend the scope chain by defining functions 3. Executive functions, each function runtime will produce an execution environment, js for each execution environment associated with a variable object, all the variables defined in the environment and functions are stored in the object 4. Js execution sequence is determined according to the called function, when a function is invoked, the function of environment variable object will be compressed into a stack of environment, After the function is executed, the station pops up the variable object of the function, giving control to the environment variable object of the previous executionCopy the code

Closure:

1. A function is nested within a function, and the internal function calls the variables of the external function. 2. Disadvantages: Variables are stored in memory after using closures, resulting in performance loss. 4. Solution: Delete all unused local variables before exiting the functionCopy the code