I have been learning javascript for less than a year now. I have a question in regards to ES6 syntax namely “let” and “const”. I know that they are supposed to replace “var”, but they are both block variable meaning that they cant be used outside the a block of code or function. But if you are developing a large program, when should you use"let" and “const”, and when should you revert to “var”, because it just seems easy to revert to using “var” whenever you are re-using a variable.
The large application that I work on doesn’t use var
at all. We always use const
if the value is never reassigned and let
if it is.
1 Like
There are vanishingly few valid uses for var
: if you need the ability to reassign you get with let
, you almost always want the better scoping rules + inability to redeclare variables in the same scope that you get with that over var