JS is executed in sequence;
However, in JS, Var and function are precompiled;
alert (show); function Show () { var A; }
For example the above code, alert will output function.
But for the pre-compilation of Var, it was just the wrong idea.
The following code, the a output is undefined.
B will directly error, B is not defined.
alert (a); alert (b); var A;
Summary of the following points:
1.js is executed sequentially during the page load process. But chunking is precompiled and executed.
2.JS performs a similar "precompiled" operation before execution, and pre-declares the variable to predefine the 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.
3. (note) It is not a full-text compilation in the execution, but a block compilation, that is, a script block, precompiled and then execute, and then (in order) the next script block, precompiled and then execute, but at this time the data in a block can be used, but the next block of functions, declared variables are not available.
4. The variable does not declare the reference, will error, but the object method, object variable is not declared, is undefined
5. In the function, the variable is not declared in the assignment, it will be considered as a global variable, declared with Var as the function variable
6. 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) does not have an effect if the function is not executed, but an execution function that begins the function precompilation error.
JS Variable pre-compilation