var everything was global, with
var it was better but still weird. ES6 brings us
const with proper lexical scoping, which makes it easier to understand where a variable is and isn’t defined.
Constants follow the same scoping rules, but their value cannot be reassigned.
const protects you against accidentally changing variables. It’s good to use it for everything by default.
Careful, though. Constants are tricky with arrays and objects. The reference becomes constant, but the value does not.
Head and Editor in Chief of EcmaScript2017 Journal. Senior JS Back-end Full stack developer and software architect.