forked from WangJia-mm/JavaScript201708
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path9-scope.html
More file actions
71 lines (63 loc) · 1.6 KB
/
9-scope.html
File metadata and controls
71 lines (63 loc) · 1.6 KB
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
67
68
69
70
71
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>作用域</title>
</head>
<body>
<script>
// console.log(a, b, c);
// var a = 12,
// b = 13,
// c = 14;
// function fn(a) {
// console.log(a, b, c);
// a = 30;
// var b = 10;
// c = 20;
// console.log(a, b, c);
// }
// fn(100);
// console.log(a, b, c);
/*
* 变量提升:
* var n; var s; fn = xxxfff000;
*/
// var n = 9;
// var s = 'str';
// function fn() {
// /*
// * 私有作用域中的形参赋值和变量提升
// * var n; (n是私有的变量)
// */
// console.log(n);//->undefined
// console.log(s);//->window.s =>'str'
// n = 7;//->私有的n=7
// var n = 6;//->私有的n=6
// }
// fn();
// console.log(n);//->9
// var n = 9;
// function fn() {
// /*
// * 变量提升和形参赋值都没有
// */
// console.log(n);//->window.n =>9
// n = 7;//->window.n=7
// }
// fn();
// console.log(n);//->7
// function fn() {
// console.log(n);//->Uncaught ReferenceError: n is not defined
// n = 7;
// }
// fn();
// console.log(n);
function fn() {
n = 7;//->全局下也没有N这个变量,此时相当于给window增加了一个n的属性,属性值是7
}
fn();
console.log(n);//->7
</script>
</body>
</html>