mirror of
https://github.com/airbnb/javascript.git
synced 2026-04-25 03:00:19 -04:00
[editorial] add var info to let/const section
This commit is contained in:
committed by
Jordan Harband
parent
dc3af3a90e
commit
5641278fa1
@@ -139,18 +139,22 @@ Other Style Guides
|
||||
```
|
||||
|
||||
<a name="references--block-scope"></a><a name="2.3"></a>
|
||||
- [2.3](#references--block-scope) Note that both `let` and `const` are block-scoped.
|
||||
- [2.3](#references--block-scope) Note that both `let` and `const` are block-scoped, whereas `var` is function-scoped.
|
||||
|
||||
```javascript
|
||||
// const and let only exist in the blocks they are defined in.
|
||||
{
|
||||
let a = 1;
|
||||
const b = 1;
|
||||
var c = 1;
|
||||
}
|
||||
console.log(a); // ReferenceError
|
||||
console.log(b); // ReferenceError
|
||||
console.log(c); // Prints 1
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
**[⬆ back to top](#table-of-contents)**
|
||||
|
||||
## Objects
|
||||
|
||||
Reference in New Issue
Block a user