-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScoping.js
More file actions
34 lines (30 loc) · 959 Bytes
/
Copy pathScoping.js
File metadata and controls
34 lines (30 loc) · 959 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"use strict";
//------------------------------------------------------------------------------
// Block-Scoped Variables
// Block-scoped variables (and constants) without hoisting.
// http://es6-features.org/#BlockScopedVariables
//------------------------------------------------------------------------------
for (let i = 0; i < a.length; i++) {
let x = a[i]
}
for (let i = 0; i < b.length; i++) {
let y = b[i]
}
let callbacks = []
for (let i = 0; i <= 2; i++) {
callbacks[i] = function () { return i * 2 }
}
callbacks[0]() === 0
callbacks[1]() === 2
callbacks[2]() === 4
//------------------------------------------------------------------------------
// Block-Scoped Functions
// Block-scoped function definitions.
// http://es6-features.org/#BlockScopedFunctions
//------------------------------------------------------------------------------
function foo () { return 1 }
foo() === 1
{
function foo () { return 2 }
foo() === 2
}