What Sass variable scopes do you know and what are the differences between them?
Experience Level: Junior
Tags: Sass
Answer
Sass has two variable scopes. Global scope and local scope.
- Global scope variables can be declared outside of a function and a mixin
- Local scope variables are declared inside of blocks (between curly braces)
$color1: lime;
@mixin box($width, $height) {
$color2 : blue;
height: $height;
width: $width;
border: solid 1px $color2;
background: lime;
}
.rectangle {
@include box(30px, 80px);
}
Related Sass job interview questions
What is Interpolation in Sass and when would you use it?
Sass JuniorIn Sass, can you declare two different variables that have the same name and different scope? Describe what happens in such situation.
Sass JuniorIn Sass, what comments are compiled into CSS and what comments are not?
Sass JuniorWhat operators can you use in Sass expressions?
Sass JuniorWhat is Nesting in Sass and how does it help with organization of your styles?
Sass Junior