@@ -18,7 +18,8 @@ chain all the way up to the window scope to find where the variable was
18
18
previously defined. If the variable wasn't previously defined, it will be
19
19
defined in the global scope, which can have extremely unexpected consequences.
20
20
21
- <javascript caption =" Functions have access to variables defined in the same scope " >
21
+ ``` js
22
+ // Functions have access to variables defined in the same scope
22
23
var foo = ' hello' ;
23
24
24
25
var sayHello = function () {
@@ -27,19 +28,21 @@ var sayHello = function() {
27
28
28
29
sayHello (); // logs 'hello'
29
30
console .log (foo); // also logs 'hello'
30
- </ javascript >
31
+ ```
31
32
32
- <javascript caption =" Code outside the scope in which a variable was defined does not have access to the variable " >
33
+ ``` js
34
+ // Code outside the scope in which a variable was defined does not have access to the variable
33
35
var sayHello = function () {
34
36
var foo = ' hello' ;
35
37
console .log (foo);
36
38
};
37
39
38
40
sayHello (); // logs 'hello'
39
41
console .log (foo); // doesn't log anything
40
- </ javascript >
42
+ ```
41
43
42
- <javascript caption =" Variables with the same name can exist in different scopes with different values " >
44
+ ``` js
45
+ // Variables with the same name can exist in different scopes with different values
43
46
var foo = ' world' ;
44
47
45
48
var sayHello = function () {
@@ -49,9 +52,10 @@ var sayHello = function() {
49
52
50
53
sayHello (); // logs 'hello'
51
54
console .log (foo); // logs 'world'
52
- </ javascript >
55
+ ```
53
56
54
- <javascript caption =" Functions can see changes in variable values after the function is defined " >
57
+ ``` js
58
+ // Functions can see changes in variable values after the function is defined
55
59
var myFunction = function () {
56
60
var foo = ' hello' ;
57
61
@@ -66,9 +70,10 @@ var myFunction = function() {
66
70
67
71
var f = myFunction ();
68
72
f (); // logs 'world' -- uh oh
69
- </ javascript >
73
+ ```
70
74
71
- <javascript caption =" Scope insanity " >
75
+ ``` js
76
+ // Scope insanity
72
77
// a self-executing anonymous function
73
78
(function () {
74
79
var baz = 1 ;
@@ -86,4 +91,4 @@ bar(); // bar is defined outside of the anonymous function
86
91
87
92
bim (); // bim is not defined outside of the anonymous function,
88
93
// so this will result in an error
89
- </ javascript >
94
+ ```
0 commit comments