Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Commit

Permalink
Add let keyword in ES6
Browse files Browse the repository at this point in the history
  • Loading branch information
sicktastic committed May 13, 2016
1 parent 0ea87bf commit f68956e
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions es6/let_keyword.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Original
var message = "hi";

{
var message = "bye";
}

console.log(message); //outputs "bye"

// Let
let message = "hi";

{
let message = "bye";
}

console.log(message); //outputs "hi"

// Example
var fs = [];

for(var i=0; i <10; i++) {
fs.push(function() {
console.log(i);
})
}

fs.forEach(function (f) {
f();
})

// Output
// 10
// 10
// 10
// 10
// 10
// 10
// 10
// 10
// 10
// 10

var fs = [];

for(let i=0; i <10; i++) {
fs.push(function() {
console.log(i);
})
}

fs.forEach(function (f) {
f();
})

// Output
// 0
// 1
// 2
// 3
// 4
// 5
// 6
// 7
// 8
// 9

0 comments on commit f68956e

Please sign in to comment.