Skip to main content

🛸 Shadowing

Useful resources:

What is shadowing ?​

When you have two or more variables, each in different scope, with the same lexical names.

The city variable (parameter) at line 3 shadows the variable city at line 1. That's why re-assignment of city at line 4 only affects the inner variable, not the outer one.

Illegal Shadowing​

Not all combinations of declaration shadowing are allowed. let can shadow var, but var cannot shadow let

var at line 4 is trying to 'cross the boundary' of let declaration.

valid. if there is a function boundary in between