-
JS is executed sequentially during the page loading process. But chunking is precompiled and executed.
-
JS performs a "pre-compilation" Operation before execution, and pre-declares the variable before the predefined function.
-
Notice at this time that it is a declaration, not a definition, such as: var a = 1; In precompilation, just "var a" is not assigned, i.e. A is undefined at the end of precompilation.
-
(note) It is not the full-text compilation in the execution, but the block compilation, that is, a script block, pre-compiled and then executed, and then (in order) the next script block, precompiled and then execute, but at this time the data in the previous block is available, but the next block of the function, declared variables are not available.
-
The variable does not declare the reference, will error, but the object method, object variable is not declared, is undefined
-
In a function where the variable is not declared, it is considered a global variable, and the function variable is declared with Var
-
When executing a function, it is compiled and executed, but it is important to note that code in a function definition (that is, curly braces) is not affected if the function is not executed, but an execution function that begins the function precompilation error.
JS Scope and pre-compilation (reprint learning ... )