From c41b471dcc2e3afb384e0ee0100d2e6ecf1724b3 Mon Sep 17 00:00:00 2001 From: antwonlee Date: Fri, 13 May 2016 11:06:39 -0500 Subject: [PATCH] Add let keyword sample 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 --- es6/let_keyword.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/es6/let_keyword.js b/es6/let_keyword.js index a91bb0b..1d09fd8 100644 --- a/es6/let_keyword.js +++ b/es6/let_keyword.js @@ -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();