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 sample
Browse files Browse the repository at this point in the history
Block scoping can be surprising, and sometimes confusing, in Javascript. With
es6, we have access to the let keyword to remove this pain

Source: https://egghead.io/lessons/the-let-keyword#/tab-code
  • Loading branch information
sicktastic committed May 13, 2016
1 parent f68956e commit c41b471
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions es6/let_keyword.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,33 @@ fs.forEach(function (f) {
// 7
// 8
// 9

function varFunc(){
var previous = 0;
var current = 1;
var i;
var temp;

for(i = 0; i < 10; i+=1){
temp = previous;
previous = current;
current = temp + current;
}
console.log(current);
}

function letFunc(){
let previous = 0;
let current = 1;

for(let i = 0; i < 10; i+=1){
let temp = previous;
previous = current;
current = temp + current;
}

console.log(current);
}

varFunc();
letFunc();

0 comments on commit c41b471

Please sign in to comment.