The let keyword in ES6

Share this video with your friends

Send Tweet

Block scoping can be surprising, and sometimes confusing, in Javascript. With es6, we have access to the let keyword to remove this pain.

NadGu
NadGu
~ 7 years ago

Let me understand well: if I declare the vars of varFunc() like you did in letFunc() the result doesn't change; but if I declare vars of letFunc() like those in varFunc() I get undefined. So: for es5 var I can access anywhere in the scope the variables I have declared whitin that scope (due to hoisting) but for es6 let I can access the variables only where I have declared them? Should I suppose that let's block scope is a kind of work-around to the js hoisting? Please let me know