Shadowing occurs when a local variable shares the same name as a global variable, causing the program to prioritize the local variable within that scope.
Understanding Scope and Lifetime of Variables
What is variable shadowing?
The answer
More FAQs in Understanding Scope and Lifetime of Variables
Scope refers to the specific block or region of code where a variable is visible, accessible, and can be modified.
Global variables can be modified by any part of the program, making it extremely difficult to track down bugs when data changes unexpectedly.
Block scope means a variable is only accessible within the specific {} brackets it was defined in, such as inside an if-statement or a for-loop.
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.