-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4-Scope Chain-II.html
41 lines (35 loc) · 903 Bytes
/
4-Scope Chain-II.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
<!DOCTYPE html>
<html>
<head>
<title>Scope Chain</title>
</head>
<p>
<ul>
<li>When you have nested functions you can create a scope 'Chain'</li>
<li>The browser travels up this chain when looking for a variables value</li>
</ul>
</p>
<body>
<script>
var myVar = "A global Variable";
function grandParent() {
var myVar = "A Variable local to grandParent()";
console.log(myVar);
function parent() {
var myVar = "A Variable local to parent()";
console.log(myVar);
function child() {
var myVar = "A Variable local to child()";
console.log(myVar);
}
child();
window.child = child;
}
parent();
window.parent = parent;
}
grandParent();
window.grandParent = grandParent;
</script>
</body>
</html>