let

The keyword 'let' was added in ECMAScript 2015 and can be used as an alternative to 'var'.
A variable declared using "let" has block scope.
A variable declared using "let" is not hoisted.
This variable can be reassigned

function myFunction() { 
   var x = 100;
   if (true) {
      let x = 200;
   }
   console.log(x); // x is 100
}

The let statement creates a new block scoped variable.


Redeclaring

It is not possible to redeclare an existing variable as a let in the same scope.
(regardless of whether it was declared with a var or a let)
Cannot be redeclared within its scope




© 2020 Better Solutions Limited. All Rights Reserved. © 2020 Better Solutions Limited TopPrevNext