What are All The Differences between var and let ?
All the above things forced ECMA to come up with a new set of standards, ES6, which is, not only solved most of the issues that were present in its earlier standards, but also made it more similar to other programming languages.
One of the keyword introduced to solve the earlier issues was ‘let’.
Have a look on the following code
Temporal Dead Zones
We can access a variable declared by using the keyword ‘var’ even before creating it.
Attaching to the window object
When working with the client side applications, browsers automatically attach the variables declared with the keyword ‘var’ to the global ‘window’ object. It do not happen with the keywords defined with ‘let’ keyword.
Note that the above example do not work in Node JS, as we will not have ‘window’ (global) object in Node JS.
Creation of Closures
ES5 solution is
ES6 Solution for the above problem: