JS - Best Practices (let, const and var)
let and const are block scoped.
Therefore, referencing block-scoped identifiers before they are defined will produce a ReferenceError.
console.log(x); // ReferenceError: x is not defined
Use const for all references; avoid using var.
If you must reassign references, use let instead of var.
let is block-scoped rather than function-scoped like var.