Skip to content

Commit 6464c21

Browse files
committed
converted the 'scope' page to the new code conventions
1 parent 8c2242c commit 6464c21

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

page/javascript-101/scope.md

+15-10
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ chain all the way up to the window scope to find where the variable was
1818
previously defined. If the variable wasn't previously defined, it will be
1919
defined in the global scope, which can have extremely unexpected consequences.
2020

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
2223
var foo = 'hello';
2324

2425
var sayHello = function() {
@@ -27,19 +28,21 @@ var sayHello = function() {
2728

2829
sayHello(); // logs 'hello'
2930
console.log(foo); // also logs 'hello'
30-
</javascript>
31+
```
3132

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
3335
var sayHello = function() {
3436
var foo = 'hello';
3537
console.log(foo);
3638
};
3739

3840
sayHello(); // logs 'hello'
3941
console.log(foo); // doesn't log anything
40-
</javascript>
42+
```
4143

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
4346
var foo = 'world';
4447

4548
var sayHello = function() {
@@ -49,9 +52,10 @@ var sayHello = function() {
4952

5053
sayHello(); // logs 'hello'
5154
console.log(foo); // logs 'world'
52-
</javascript>
55+
```
5356

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
5559
var myFunction = function() {
5660
var foo = 'hello';
5761

@@ -66,9 +70,10 @@ var myFunction = function() {
6670

6771
var f = myFunction();
6872
f(); // logs 'world' -- uh oh
69-
</javascript>
73+
```
7074

71-
<javascript caption="Scope insanity">
75+
``` js
76+
// Scope insanity
7277
// a self-executing anonymous function
7378
(function() {
7479
var baz = 1;
@@ -86,4 +91,4 @@ bar(); // bar is defined outside of the anonymous function
8691

8792
bim(); // bim is not defined outside of the anonymous function,
8893
// so this will result in an error
89-
</javascript>
94+
```

0 commit comments

Comments
 (0)