javascript 变量提升

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
try {
function test_1() {
print('hello');
const print = (string) => { console.log(string); }
}
test_1();
} catch (error) {
console.log('test_1', error)
}

try {
function test_2() {
print('hello');
function print(string) { console.log(string); }
}
test_2();
} catch (error) {
console.log('test_2', error)
}

try {
function test_3() {
print('hello');
}
const print = (string) => { console.log(string); }
test_3();
} catch (error) {
console.log('test_3', error)
}

try {
function test_4() {
print('hello');
}
test_4();
const print = (string) => { console.log(string); }
} catch (error) {
console.log('test_4', error)
}


try {
function test_5() {
print('hello');
}
setTimeout(() => {
test_5()
}, 100);
const print = (string) => { console.log(string); }
} catch (error) {
console.log('test_5', error)
}