let me explain 😝#
let keyword is a better replacement for var for the below reasons. This got introduced in ES6 (duh!)
- It has better scoping which is block scope. That means you can use
letmore confidently in loops without polluting the scope of the enclosing function.
- Because of block scope, the whole suite of scope related issues can be avoided.
- Unlike var, values declared using
letare not hoisted, so you will not be able to use those values before the declaration.
- At root level if you declare a value using
let, this will not add it to the window global object.
letvalues will throw an error.
More discussion in stack-overflow.