Skip to content

Commit 48a1d04

Browse files
authored
Update README.md
1 parent 0ab6fbc commit 48a1d04

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,22 @@ This is why, maybe, you confused this construction with an event-handler for win
4141
**[⬆ Back to Top](#table-of-contents)**
4242

4343
3. ### What's the difference between using “let” and “var” to declare a variable in ES6?
44+
Main difference is scoping rules. Variables declared by ``var`` keyword are scoped to the immediate function body (hence the function scope) while ``let`` variables are scoped to the immediate enclosing block denoted by `` { } `` (hence the block scope).
45+
```typescript
46+
function run() {
47+
var foo = "Foo";
48+
let bar = "Bar";
49+
50+
console.log(foo, bar);
51+
52+
{
53+
let baz = "Bazz";
54+
console.log(baz);
55+
}
56+
57+
console.log(baz); // ReferenceError
58+
}
59+
60+
run();
61+
```
62+
**[⬆ Back to Top](#table-of-contents)**

0 commit comments

Comments
 (0)