1. By default, the browser parses the HTML code from top to bottom, and of course the script is embedded in the HTML, so it is also in this order, and the files that are introduced outside do not change this order.
2. Any JavaScript code will be compiled before execution
3. When parsing to script the browser invokes the JS parser, usually the JS parser is pre-compiled, then parsed, and the parser compiles the variables and function declarations. if it has not been previously declared, the compiler declares a variable at the current scope, initializes it, but the variable is not assigned a value at this time
In this case, the compiler will first declare a variable in the current scope, initialize it, that is, num (if it was not previously declared), But at this time the variable is not assigned , so there will be undefined
Next, the engine looks for the variable in the scope, and if it can find it, it will be assigned a value, so there will be 1.
4. Function compilation
When a function name is the same, the following function replaces the previous function
The 5.js parser is precompiled and parsed according to the script fragment , compiles the first script fragment and executes, then compiles a second script fragment and executes
6.
In different script snippets, variables can be shared (this is for global variables and functions that can be shared). Local variables should be placed in the function.
If there is a problem with this code when executing a script snippet, the code following the current script is stopped, but there is no effect on the subsequent script fragment.
The order in which JavaScript is executed