Variable promotion (sound)

Before executing the code, JS will pre-declare the code with var and function

* Var is a declaration that does not define a declaration with functionCopy the code

Variable promotion only elevates the left-hand side of the equals sign

Variable promotion is a variable commission regardless of the conditionCopy the code

Function declarations in advanced browsers are only declared in conditional clauses or looping data.

scope

Scope is the area where code can act. Scope is the stack memory where reference data types are stored. Scope is the stack memory where value types are storedCopy the code
  • Global scope:
A page opens with a global scope. A page has only one global scopeCopy the code
  • Private scope:
A private scope is formed during function executionCopy the code

A variable in a private scope might not be a private variable in that private scope, and then the value of that variable needs to goIf it is still not a private variable in the parent scope, it then looks up until the window location is found. If it is not, an error is reported

When the function is executed, the argument is assigned and the variable is promoted

  • Block-level scope
The part of es6 that is enclosed by curly braces in an assertion loop is added onlyletAnd const can recognize block-level scope. There is no block-level scope for varCopy the code

Variables declared in a global scope are called global variables

Variables declared in private scopes are called private variables; Parameters are also private variables.

Superior scope:

The private scope that is created when a function is executed, there will always be a parent scope, and who is the parent scope of the private scope, it doesn’t matter where the function is executed, it just matters what scope the function is defined in