What is variable shadowing?
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.
Verify This Answer
Cross-check this information using these trusted sources:
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
