The
javascript is an interpreted language, and its execution is top-down. Because each browser has a different understanding of it, so we need to understand the order of the JS implementation of the sequence
Introduction JavaScript is an interpreted language, and its execution is top-down. But the browser for the "Top-down" understanding is subtle, and the code upstream and downstream is the program flow for the correct operation of the program is also critical. So it is necessary for us to understand the order of JS execution. To this end, I designed the following eight experiments to obtain the most accurate results. Experiment code as follows: <script type= "Text/javascript" > //Experiment one: function T (a) { Alert ("[t (a)]a:" + a); } function T (A, b) { alert ("[T (A, B)]a:" + A + ", B:" + b); } t (1); //Results: //[t (A, B)]a:1, b:undefined //Experiment two: function T (A, b) { alert ("[T (A, B )]a: "+ A +", B: "+ B"; } function T (a) { alert ("[t (a)]a:" + a); } T (1); //Result: & nbsp [T (a)]a:1 //Experiment three: function T (a) { alert ("[t (a)]a:" + a); } function T (A, B) &nb Sp { alert ("[T (A, B)]a:" + A + ", B:" + b); } t (1, 2); //Results: //[t (A, B)]a:1, b:2 / /Experiment four: function T (A, b) { alert ("[T (A, B)]a:" + A + ", B:" + b); } function T (a) { Alert ("[t (a)]a:" + a); } t (1, 2); //Results: //[t (a)]a:1 //Experiment five function T (a) & nbsp { alert ("[t (a)]a:" + a); } T (1); function T (A, b) { alert ("[T (A, B)]a:" + A + ", B:" + b); } //Results: //[t (A, B)]a:1, b:undefined //experiment six function T (a) { alert ("[t ( A)]a: "+ a"; } t (1, 2); function T (A, b) { alert ("[T (A, B)]a:" + A + ", B:" + b); }&NB Sp Results: //[t (A, B)]a:1, b:2 //Experiment VII function T (A, b) { alert ("[T (A, B)]a:" + A + ", B:" + b); } T (1); function T (a) { alert ("[t (a)]a:" + a); } //Results: //[t (a)]A:1&NB Sp //Experiment eight function T (A, b) { alert ("[T (A, B)]a:" + A + ", B:" + b); } t (1, 2); func tion T (a) { alert ("[t (a)]a:" + a); } //Results: //[t (a)]a:1 </script> & nbsp PostScript &NBSp When you define a JavaScript function, the function name is the identity of the function object, and the number of parameters is just the property of the function. It is not possible to implement overloads by defining a function with a different number of parameters. Call function, JS through the function name to find the corresponding function object, and then according to the function definition of the parameters, and the expression parameter list in order to match, redundant parameters, not enough parameters to undefined processing, and then execute the function code. So when you define a function, you usually put the required arguments at the top of the argument list, and the optional arguments are placed behind the required parameters. Considerations One, the results of the eight experiments were obtained through 360 browsers (Version/kernel: 6.3.1.142/21.0.1180.89) and Firefox (version: 27.0.1). II, the above eight experiments are independent of each other, please run separately to get the correct results.