const is a signal that the variable won’t be reassigned.
let is a signal that the variable may be reassigned
Additional things to ponder:
- Use
constby default - Use
letonly if rebinding is needed -
constdoes not indicate that a value is ‘constant’ or immutable.const foo = {}; foo.bar = 10; console.log(foo.bar); // --> 10Only the binding is immutable. ie using an assignment operator or a unary or postfix — or ++ operator on a const variable throws a TypeError exception
-
ES6
constandletare hoisted too. Although the identifiers has the same memory reference from compile time, they cannot be accessed before declaration in the code. (but not as we thought the declaration would be physically moved to the top in the scope) 😉