DEV Community

Discussion on: Is`let` the new `var` in Javascript?

Collapse
 
amt8u profile image
amt8u

As far as you understand the difference between var, let and const you are free to use any of those. The issue comes in when you are working with a team.

While many would understand how hoisting works in javascript, a lot of the people coming from other languages do not. var is certainly not easy to digest specially when combined with function declarations and loops.

In that case you would like the team to follow certain guidelines. You can restrict the use of var and it should work. There is no performance penalty and in addition you get the power of block scoping and also making it easier for others to write programs.

Collapse
 
amitkhonde profile image
Amit Khonde

Completely agree here. It highly depends on the team and the style of writing code. But I also believe that using var (that this variable is used throughout the function) or let (that this variable is used only in the current block) carries a special meaning. And you are correct. Concepts of var are not easy to digest.

Collapse
 
joelbonetr profile image
JoelBonetR 🥇

well, "you are free to use any of those" it's not that "as is" at all. If you use const and you don't know how consts works you'll get stuck trying to imagine why this fkin const is not changing their value even set on a lefthand just before. 😆

Collapse
 
amt8u profile image
amt8u

Yeah, of course - been there:-D. But I guess, engines report the re-assignment error properly. At least on browser you get - Uncaught TypeError: Assignment to constant variable. And I did start with "as far as you understand the difference", If you don't then you can always follow what others are doing. Use let everywhere.