Introduction
Javascript is an interpreted language and its execution is top-down. However, each browser has a slightly different understanding of "top-down", and the upstream and downstream of the code, that is, the program flow, are crucial for the correct operation of the program. So we need to deeply understand the execution order of js. To this end, I designed the following eight experiments to obtain the most accurate results.
Experiment
Postscript
When defining a JavaScript function, the function name is the identifier of the function object, and the number of parameters is just an attribute of the function. It is not possible to implement overloading by defining functions with different numbers of parameters.
When calling a function, js finds the corresponding function object through the function name, and then matches the expression parameter list in order according to the parameters when the function is defined. The excess parameters are discarded, and the insufficient parameters are treated as undefined, and then the function is executed. code.
So when defining a function, the required parameters are usually placed at the beginning of the parameter list, and the optional parameters are placed after the required parameters.
Notes
1. The results of the above eight experiments are obtained through 360 browser (version/kernel: 6.3.1.142/21.0.1180.89) and Firefox browser (version: 27.0.1 ) is obtained by running.
2. The above eight experiments are independent of each other. Please run them separately to get correct results.