Skip to content

Commit 5641278

Browse files
Kelta-Kingljharb
authored andcommitted
[editorial] add var info to let/const section
1 parent dc3af3a commit 5641278

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,22 @@ Other Style Guides
139139
```
140140
141141
<a name="references--block-scope"></a><a name="2.3"></a>
142-
- [2.3](#references--block-scope) Note that both `let` and `const` are block-scoped.
142+
- [2.3](#references--block-scope) Note that both `let` and `const` are block-scoped, whereas `var` is function-scoped.
143143

144144
```javascript
145145
// const and let only exist in the blocks they are defined in.
146146
{
147147
let a = 1;
148148
const b = 1;
149+
var c = 1;
149150
}
150151
console.log(a); // ReferenceError
151152
console.log(b); // ReferenceError
153+
console.log(c); // Prints 1
152154
```
153155

156+
In the above code, you can see that referencing `a` and `b` will produce a ReferenceError, while `c` contains the number. This is because `a` and `b` are block scoped, while `c` is scoped to the containing function.
157+
154158
**[⬆ back to top](#table-of-contents)**
155159

156160
## Objects

0 commit comments

Comments
 (0)