In JavaScript, I recently came across the const keyword. It appears to be used to create immutable variables, and I checked it to guarantee that it cannot be redefined (in Node.js):
const x = 'const';
const x = 'not-const';
// Will give an error: 'constant 'x' has already been defined'
I understand that it isn't yet standardized across all browsers - but I'm primarily interested in the context of Node.js V8, and I've seen that some developers/projects appear to favor it excessively when the var keyword may achieve the same result.
1. When should const be used in place of var?
2. Should it be used whenever a variable that will not be re-assigned is declared?
3. Does it make a difference if var is used instead of const or vice versa?