Why let is better than var

So the issue with var is that it is has some weird scoping rules - it’s scoped according the function it is defined in or if outside of a function to the window object.

The let word allows one to define variables in way which is more typical to other languages where the scope of the variable is block scoped.

{ var Value1 = 10; let Value2 = 20; } console.log(Value1); // this will work console.log(Value2); // this will fail

There is no need to use var anymore in Javascript.

 

Related pages