Re-declarations and Shadowing
With var declarations, we mentioned that it didn’t matter how many times you declared your variables; you just got one.
function f(x) {
var x;
var x;
if (true) {
var x;
}
}
In the above example, all declarations of x actually refer to the same x, and this is perfectly valid. This often ends up being a source of bugs. Thankfully, let declarations are not as forgiving.
let x = 10;
let x = 20; // error: can't re-declare 'x' in the same scope
The variabl