var). Nowadays I always reach for
const unless I'm forced to.
const) over a variable (
When am I forced to use
const x = "hi"; x = "bye"; // VM226:1 Uncaught TypeError: Assignment to constant variable
This way I don't bother with thinking about which declaration I should use, I'll be alerted when I have to by following a rule.
In this case I still use
const even if changes are being made.
const arr = ; arr.push(1);
let arr = ; arr = [...arr, 1];
In this case I will switch my
const to a
const over let unless I'm forced to
I just let my tools let me know if a variable is necessary. It also makes sense to use a variable (
let) when the value stored inside of it varies throughout the lifecycle of the program.