Recall & Review
beginner
What is scope in programming?
Scope is the area in a program where a variable or function is accessible or can be used.
Click to reveal answer
beginner
Why does scope matter when writing code?
Scope helps prevent mistakes by controlling where variables can be seen and changed, making programs easier to understand and fix.
Click to reveal answer
intermediate
What happens if two variables have the same name but different scopes?
They are treated as separate variables. The program uses the one in the closest scope to where it is called.
Click to reveal answer
beginner
How does scope help in real life, like in a kitchen?
Just like you keep spices in one shelf and utensils in another, scope keeps variables organized so you don’t mix things up.
Click to reveal answer
beginner
What is the difference between
local and global scope?Local scope means a variable is only available inside a function. Global scope means it can be used anywhere in the program.
Click to reveal answer
What does local scope mean?
✗ Incorrect
Local scope means the variable exists only inside the function or block where it is defined.
Why is it good to limit variable scope?
✗ Incorrect
Limiting scope helps prevent bugs by keeping variables from interfering with each other.
If a variable is defined inside a function, where can it be used?
✗ Incorrect
Variables inside a function have local scope and cannot be used outside it.
What happens if you have two variables with the same name in different scopes?
✗ Incorrect
Variables with the same name in different scopes do not interfere; the closest one is used.
Which scope allows a variable to be used anywhere in the program?
✗ Incorrect
Global scope means the variable is accessible throughout the entire program.
Explain in your own words why scope is important when writing programs.
Think about how knowing where a variable can be used helps avoid mistakes.
You got /4 concepts.
Describe the difference between local and global scope with a simple example.
Imagine a variable you can only use inside a room versus one you can use in the whole house.
You got /4 concepts.