Recall & Review
beginner
What does the
!default flag do in Sass?It sets a variable only if it has not been set before. This means the variable keeps its value unless it is undefined, then the
!default value is used.Click to reveal answer
beginner
How do you write a Sass variable with a default value of blue?
$color: blue !default;This means
$color will be blue unless it was already set to something else.Click to reveal answer
intermediate
Why use
!default in Sass variables?It helps avoid overwriting variables when importing files. You can set a default style but allow users to customize by setting the variable before importing.
Click to reveal answer
beginner
What happens if you set a variable without
!default after it was already set?The new value will overwrite the old one, no matter what.
!default prevents overwriting if the variable exists.Click to reveal answer
beginner
Can
!default be used with any Sass variable type?Yes, it works with colors, numbers, strings, lists, maps, or any value type in Sass.
Click to reveal answer
What does
$font-size: 16px !default; do if $font-size is already set to 14px?✗ Incorrect
The
!default flag only sets the variable if it is not already set. Since $font-size is 14px, it stays 14px.Why is
!default useful when creating reusable Sass libraries?✗ Incorrect
Using
!default lets users set variables before importing the library, so the library uses those values instead of defaults.Which of these is a correct way to set a default variable in Sass?
✗ Incorrect
The correct syntax is
$variable: value !default; with a colon and the !default flag after the value.If you want to ensure a variable is always set to a specific value, should you use
!default?✗ Incorrect
Omitting
!default means the variable will be overwritten no matter what, ensuring the value is set.Can
!default be used multiple times on the same variable in different files?✗ Incorrect
The first time the variable is set, it keeps that value. Later
!default assignments do not overwrite it.Explain how the
!default flag works in Sass variables and why it is useful.Think about how you can set a backup value that only applies if no other value exists.
You got /4 concepts.
Describe a real-life situation where using
!default in Sass variables would help you manage styles better.Imagine you make a button style library others use and want them to change colors easily.
You got /4 concepts.