Perhaps the most important thing you can learn to be a better coder is tokeep things simple. In the context of identifiers, that means that a single identifier should only be used to represent a single concept.
Sometimes its tempting to create an identifier to represent some data and then use that identifier as a temporary place to store values in transition from one representation to another.
For instance, you may be after a query string parameter value, and start by storing an entire URL, then just the query string, then the value. This practice should be avoided.
Its easier to understand if you use one identifier for the URL, a different one for the query string, and finally, an identifier to store the parameter value you were after.
If I dont need to reassign,`const` is my default choiceover`let`because I want the usage to be as clear as possible in the code.
I use`let`when I need to reassign a variable. Because I use one variable to represent one thing,the use case for`let`tends to be for loops or mathematical algorithms.
I dont use`var`in production ES6 code. There is value in block scope for loops, but I cant think of a situation where Id prefer`var`over`let`. It can be handy in a REPL (Read Evaluate Print Loop) environment like the debugger or Node console when youre just experimenting and reassignment could be useful.
`const` is a signal that the identifier wont be reassigned.
`let` is a signal that the variable may be reassigned, such as a counter in a loop, or a value swap in an algorithm. It also signals that the variable will be used only in the block its defined in, which is not always the entire containing function.