-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path作用域嵌套.html
66 lines (55 loc) · 1.47 KB
/
作用域嵌套.html
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
window.onload=()=>{
//foo(3) //ReferenceError 函数运行时b未定义
// let b=3;
// function foo(a) {
// console.log(a+b)
// }
// foo(2)
// // 声明i为全局变量
// for(var i= 0;i<4;i++){
// console.log(i)
// }
// //最后一次调用++后 i值为4
// console.log(i)
for (var i=1; i<=5; i++) {
(function(x) {
setTimeout( function timer() {
console.log(x);
}, x*1000 );
})(i);
}
for (let j=1; j<=5; j++){
setTimeout( function timer() { console.log(j);
}, j*1000 );
}
a() //'a'
function a() {
console.log('a')
}
a()
console.log(b) //undefined
var b='b'
animate(2) //函数提升
function animate(x) {
console.log(x)
setTimeout(()=>{
console.log(y) //变量没有提升
console.log(x)//变量没有提升
console.log(Math.abs(x)) //abs undefine 为NAN
var x= Math.abs(x)
var y='11'
console.log(x) //输出NaN
},10)
}
}
</script>
</body>
</html>