-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy path1-let.js
More file actions
32 lines (28 loc) · 743 Bytes
/
1-let.js
File metadata and controls
32 lines (28 loc) · 743 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
// Understanding function scoped and variable hoisting
// Run in : Firefox browser > Web Developer > Web Console
var jsFuture = "es6";
(function () {
// var jsFuture = undefined;
// variable hoisting
if (!jsFuture) { var jsFuture = "es5"; }
console.log(jsFuture); // "es5"
}());
// ES5 var
// Run in : Firefox browser > Web Developer > Web Console
var es = [];
for (var i = 0; i < 10; i++) {
es[i] = function () {
console.log("Upcoming edition of ECMAScript is ES" + i);
};
}
es[6](); // 10
// ES6 let
// Run in : Firefox browser > Web Developer > Web Console
var es = [];
for (var j = 0; j < 10; j++) {
let c = j;
es[j] = function () {
console.log("Upcoming edition of ECMAScript is ES" + c);
};
}
es[6](); // 5