SASS Operators and Expressions 1 — Questions and Answers
Question 1: Which arithmetic operators does Sass support?
- +, -, *, /, % (Correct answer)
- +, -, *, **, //
- +, -, ×, ÷
- add, sub, mul, div
Correct answer: +, -, *, /, %
Sass supports addition, subtraction, multiplication, division, and modulo in arithmetic expressions.
Question 2: How do you perform division in modern Sass (Dart Sass)?
- math.div($a, $b) (Correct answer)
- $a / $b
- divide($a, $b)
- $a // $b
Correct answer: math.div($a, $b)
In Dart Sass, `/` is reserved for CSS shorthand, so `math.div()` from `sass:math` is used for division.
Question 3: What does the `%` operator do in Sass?
- Returns the remainder of a division (Correct answer)
- Converts a number to a percentage
- Marks a placeholder selector
- Applies a percentage unit
Correct answer: Returns the remainder of a division
The `%` modulo operator in Sass returns the remainder when dividing two numbers.
Question 4: What is the result of `10px + 5px` in Sass?
- 15px (Correct answer)
- 10px5px
- 15
- error
Correct answer: 15px
Sass can add compatible units together, so `10px + 5px` results in `15px`.
Question 5: What happens when you add values with incompatible units in Sass, e.g., `10px + 5em`?
- A compilation error is thrown (Correct answer)
- Units are ignored and numbers are added
- The result is in the first unit
- The result is in rem
Correct answer: A compilation error is thrown
Sass throws a compilation error when you attempt arithmetic on values with incompatible units.
Question 6: Which comparison operator checks if two Sass values are NOT equal?
- != (Correct answer)
- <>
- !==
- not ==
Correct answer: !=
Sass uses `!=` as the not-equal comparison operator in conditional expressions.
Which arithmetic operators does Sass support?