做网站有回扣拿吗,广州网络营销公司,沂南做网站,网络认证工程师JavaScript执行步骤 1.检查通篇的语法错误2.预编译过程3.解释一行#xff0c;执行一行 1 (a)2 test()3 function test() {4 console.log(1) // 15 }6 7 (b)8 console.log(a); // undefined9 var a ;
10
11 函数申明整体提升#xff0c;变量只有申明提升…JavaScript执行步骤 1.检查通篇的语法错误2.预编译过程3.解释一行执行一行 1 (a)2 test()3 function test() {4 console.log(1) // 15 }6 7 (b)8 console.log(a); // undefined9 var a ;
10
11 函数申明整体提升变量只有申明提升赋值不提升
12
13 (c)
14 console.log(a) // function a(a){}
15 function a(a){}
16 var a 1
17
18 (d)
19 var a 1
20 b 2
21 console.log(window.b) // a window.a
22 // b window.b 暗示全局变量 imply global variable 1 (a)2 function test(){3 var a b 14 // 1.先声明 var a5 // 2.1赋值给b6 // 3.b的值赋值给a7 }8 console.log(a) // error9 console.log(window.a) // undefined
10 console.log(b) // 1
11 console.log(window.b) // 1
12
13 (b)
14 function test(a) {
15 console.log(a) // function a() {}
16 var a 1
17 console.log(a) // 1
18 function a() {}
19 console.log(a) // 1
20 var b function () {}
21 console.log(b) // function(){}
22 function d() {}
23 }
24 test(2) 函数预编译AO activation object (活跃对象函数上下文) 1 function test(a) {2 console.log(a) // function a() {}3 var a 14 console.log(a) // 15 function a() {}6 console.log(a) // 17 var b function () {}8 console.log(b) // function(){}9 function d() {}
10 }
11 test(2)
12
13 执行过程
14
15 AO {
16
17 }
18
19 -预编译过程-
20
21 第一步寻找形参和变量申明
22 AO {
23 a: undefined,
24 b: undefined
25 }
26
27 第二步实参赋值给形参
28 AO {
29 a: undefined - 2,
30 b: undefined
31 }
32
33 第三步寻找函数体的申明并赋值
34 AO {
35 a: undefined - 2 - function a() {},
36 b: undefined,
37 d: function d() {}
38 }
39
40 -代码执行过程-
41 第四步执行函数体第一句
42 // console.log(a)function a(){}
43
44 第五步执行函数体第二局
45 //a 1
46 AO {
47 a: undefined - 2 - function a() {} - 1,
48 b: undefined,
49 d: function d() {}
50 }
51
52 .... 全局预编译GO global object 全局上下文 1. 找变量2. 找函数申明3. 执行 1 (a)2 var a 13 function a() {4 console.log(2)5 }6 console.log(a) // 17 8 GO {9 a: undefined - function a(){} - 1
10 }
11
12 其实GO就是window即GO window
13
14 (b)
15 console.log(a, b) // function a(){} undefined
16 function a() {}
17 var b function () {}
18
19 GO {
20 b: undefined
21 a: function a(){}
22 } 练习 1 练习2 3 14 function test() {5 var a b 1;6 console.log(b); // 17 }8 test();9 步骤10 -预编译过程-11 1.12 GO {13 14 }15 16 2.17 GO {18 19 }20 21 AO {22 a: undefined23 }24 -执行过程-25 3.26 GO {27 b: 128 }29 30 AO {31 a: undefined32 }33 34 4.35 GO {36 b: 137 }38 39 AO {40 a: undefined - 141 }42 43 (2)44 var b 3;45 console.log(a); // function a(a){...}46 function a(a){47 console.log(a) // function a(){}48 var a 2;49 console.log(a); // 250 function a(){}51 var b 5;52 console.log(b) // 553 }54 a(1);55 56 步骤57 58 -编译过程-59 60 GO {61 b: undefined,62 a: function a(){...}63 }64 65 AO {66 a: undefined - 1 - function a(){}67 b: undefined68 }69 70 -执行过程-71 72 GO {73 b: undefined - 3,74 a: function a(){...}75 }76 77 AO {78 a: undefined - 1 - function a(){} - 279 b: undefined - 580 }81 82 83 (3)84 a 1;85 function test(){86 console.log(a); // undefined87 a 2;88 console.log(a); // 289 var a 3;90 console.log(a) // 391 }92 test()93 94 (4)95 function test(){96 console.log(b); // undefined97 if (a) {98 var b 2;99 }
100
101 c 3;
102 console.log(c) // 3
103 }
104
105 var a;
106 test();
107 a 1;
108 console.log(a); // 1
109
110 (5)
111 function test(){
112 return a;
113 a 1;
114 function a(){}
115 var a 2;
116 }
117 console.log(test()); // function a(){}
118
119
120 (6)
121 function test(){
122 a 1;
123 functin a(){}
124 var a 2;
125 return a;
126 }
127 console.log(test()); // 2
128
129 (7)
130 a 1;
131 function test(e){
132 function e(){}
133 arguments[0] 2;
134 console.log(e); // 2
135 if(a){
136 var b 3;
137 }
138 var c;
139 a 4;
140 var a;
141 console.log(b); // undefined
142 f 5;
143 console.log(c); // undefined
144 console.log(a); // 4
145 }
146 var a;
147 test(1); 转载于:https://www.cnblogs.com/wanghao123/p/10451612.html