0
0
SASSmarkup~5 mins

Variable scope (global vs local) in SASS - Quick Revision & Key Differences

Choose your learning style9 modes available
Recall & Review
beginner
What is a global variable in Sass?
A global variable in Sass is a variable declared outside any selector or function. It can be accessed anywhere in the stylesheet unless overridden by a local variable with the same name.
Click to reveal answer
beginner
What is a local variable in Sass?
A local variable in Sass is a variable declared inside a selector, function, or mixin. It only exists within that block and cannot be accessed outside it.
Click to reveal answer
intermediate
How do you make a local variable affect the global variable in Sass?
You use the !global flag when assigning a variable inside a block. This updates the global variable instead of creating a new local one.
Click to reveal answer
intermediate
What happens if you declare a variable with the same name both globally and locally in Sass?
The local variable overrides the global one inside its block. Outside the block, the global variable value is used.
Click to reveal answer
beginner
Why is understanding variable scope important in Sass?
It helps avoid unexpected styles by controlling where variables can be used or changed. It keeps stylesheets organized and easier to maintain.
Click to reveal answer
Where is a Sass variable declared outside any selector accessible?
AAnywhere in the stylesheet
BOnly inside the selector it is declared
COnly inside functions
DNowhere, it is invalid
What does the !global flag do in Sass?
ACreates a new local variable
BMakes a local variable update the global variable
CDeletes the global variable
DPrevents variable usage
If a variable is declared both globally and locally with the same name, which one is used inside the local block?
AGlobal variable
BNeither variable
CBoth variables
DLocal variable
Can a local variable in Sass be accessed outside its block?
AYes, always
BOnly if declared with !global
CNo, never
DOnly inside functions
Why should you be careful with variable scope in Sass?
ATo avoid unexpected style changes
BTo make CSS slower
CTo increase file size
DTo disable variables
Explain the difference between global and local variables in Sass and how the !global flag works.
Think about where variables can be used and changed.
You got /4 concepts.
    Describe a real-life example where variable scope in Sass helps keep your styles organized.
    Imagine managing colors or sizes in a big project.
    You got /4 concepts.