What does shadowing mean?
- Declaring a global variable with the same name as a previously declared global variable.
- Changing the value of a variable.
- Deleting and rewriting a selected piece of program code.
- Declaring a local variable with the same name as the previously declared global variable.
Answers Explanation & Hints:
Shadowing refers to the situation where a variable declared within a specific scope (such as a function or block) has the same name as a variable declared in an outer scope. As a result, the outer variable is temporarily “shadowed” or inaccessible within the inner scope, as the local variable takes precedence. This can occur when a variable is declared in a nested block, function, or another scope that has its own variable with the same name as a variable in an outer scope. The local variable “shadows” the outer variable, meaning that any references to that variable within the inner scope will refer to the local variable, not the outer one. This concept is important to understand to avoid confusion and unintended consequences when dealing with variable scoping in programming languages. |