Something Solid to Cling To
A Spoonful of Syntactic Sugar
But if you try to use modern syntax to recreate a familiar old technique, or stick it in without understanding how it actually behaves, you run the risk of:
having to debug code that worked perfectly before
introducing subtle mistakes that may catch you at runtime
creating code that fails silently when you least expect it.
When Your const Isn’t Consistent
console.log(usingVar); // undefined
var usingVar = “defined";
console.log(usingVar); // "defined"
console.log(usingLet); // error
let usingLet = "defined"; // never gets executed
console.log(usingLet); // never gets executed
This is a great convenience for block-scoped uses of variables such as iterators and loops. Previously, variables declared within loops would be available to the containing scope, leading to potential confusion when multiple counters might use the same variable name. However let can catch you by surprise if you expect your variable declared somewhere inside of one block of your script to be available elsewhere.