Bird
Raised Fist0
SASSmarkup~5 mins

sass:meta module (type-of, inspect)

Choose your learning style10 modes available
Introduction

The sass:meta module helps you check what kind of value you have and see its details. This is useful when you want to understand or debug your styles.

You want to know if a value is a color, number, string, or something else.
You need to print out a value to understand what it contains.
You are writing functions or mixins that behave differently based on the type of input.
You want to debug complex Sass variables by inspecting their content.
Syntax
SASS
@use "sass:meta";

meta.type-of($value)
meta.inspect($value)

type-of() returns the type of the value as a string like "string", "number", "color", etc.

inspect() returns a string showing the value in a readable way, useful for debugging.

Examples
This checks the type of $value, which is a number with units, so $type will be "number".
SASS
@use "sass:meta";

$value: 10px;
$type: meta.type-of($value);
This converts the color $value to a string like "#ff0000" for easy reading.
SASS
@use "sass:meta";

$value: #ff0000;
$info: meta.inspect($value);
Here, $value is a string, so type-of() returns "string".
SASS
@use "sass:meta";

$value: "hello";
$type: meta.type-of($value);
Sample Program

This Sass code uses meta.type-of() to find the type of different values and meta.inspect() to get their readable string forms. The results are set as CSS properties so you can see them in the browser.

SASS
@use "sass:meta";

$color: #3498db;
$size: 2rem;
$text: "Sass Meta";

.type-check {
  color-type: meta.type-of($color);
  size-type: meta.type-of($size);
  text-type: meta.type-of($text);
  color-inspect: meta.inspect($color);
  size-inspect: meta.inspect($size);
  text-inspect: meta.inspect($text);
}
OutputSuccess
Important Notes

Always @use "sass:meta"; before calling type-of() or inspect().

type-of() helps you write smarter styles by checking value types.

inspect() is great for debugging but usually not used in final CSS.

Summary

sass:meta helps you check and understand Sass values.

type-of() tells you the kind of value you have.

inspect() shows the value as a readable string.

Practice

(1/5)
1. What does the Sass function type-of() do?
easy
A. It changes the type of a Sass value.
B. It prints the value to the console.
C. It converts Sass code to CSS.
D. It tells you the kind of value you have in Sass.

Solution

  1. Step 1: Understand the purpose of type-of()

    This function returns the type of a given Sass value, like string, number, color, etc.
  2. Step 2: Compare options with the function's behavior

    Only It tells you the kind of value you have in Sass. correctly describes that it tells the kind of value you have.
  3. Final Answer:

    It tells you the kind of value you have in Sass. -> Option D
  4. Quick Check:

    type-of() = tells value type [OK]
Hint: Remember: type-of() reveals the value's kind [OK]
Common Mistakes:
  • Thinking type-of() changes the value type
  • Confusing type-of() with output functions
  • Assuming it converts Sass to CSS
2. Which of the following is the correct syntax to use inspect() on a Sass variable $color?
easy
A. inspect($color)
B. inspect $color;
C. inspect($color);
D. inspect $color()

Solution

  1. Step 1: Recall correct function call syntax in Sass

    Functions require parentheses around arguments and no semicolon inside the parentheses.
  2. Step 2: Check each option's syntax

    inspect($color) uses inspect($color) which is correct. inspect($color); has an extra semicolon inside parentheses, B misses parentheses, D has incorrect parentheses placement.
  3. Final Answer:

    inspect($color) -> Option A
  4. Quick Check:

    Function calls need parentheses [OK]
Hint: Use parentheses for Sass function calls [OK]
Common Mistakes:
  • Omitting parentheses for function calls
  • Adding semicolon inside function parentheses
  • Misplacing parentheses after variable
3. Given the Sass code:
$value: 10px;
$result: type-of($value);
What is the value of $result?
medium
A. "string"
B. "number"
C. "length"
D. "px"

Solution

  1. Step 1: Identify the type of $value

    The value 10px is a number with a unit in Sass, so its type is "number".
  2. Step 2: Understand what type-of() returns

    It returns the type as a string, so $result will be "number".
  3. Final Answer:

    "number" -> Option B
  4. Quick Check:

    10px is a number type [OK]
Hint: Units don't change type; 10px is still a number [OK]
Common Mistakes:
  • Thinking units create a new type like 'length'
  • Confusing string with number
  • Assuming type-of returns the unit
4. What is wrong with this Sass code?
$val: #ff0000;
$result: inspect $val;
medium
A. Missing parentheses for the inspect function call.
B. The variable $val is not defined.
C. inspect cannot be used with color values.
D. inspect requires a semicolon after the variable.

Solution

  1. Step 1: Check function call syntax

    In Sass, functions must be called with parentheses around arguments.
  2. Step 2: Identify the error in the code

    The code uses inspect $val; without parentheses, which is invalid syntax.
  3. Final Answer:

    Missing parentheses for the inspect function call. -> Option A
  4. Quick Check:

    Functions need parentheses [OK]
Hint: Always use parentheses when calling Sass functions [OK]
Common Mistakes:
  • Calling functions without parentheses
  • Assuming inspect can't handle colors
  • Thinking semicolon is needed inside function call
5. You want to create a Sass mixin that prints the type and value of any input variable for debugging. Which code correctly uses type-of() and inspect() together?
hard
A. @mixin debug($var) { content: "Type: $var.type, Value: $var.inspect"; }
B. @mixin debug($var) { content: "Type: type-of($var), Value: inspect($var)"; }
C. @mixin debug($var) { content: "Type: #{type-of($var)}, Value: #{inspect($var)}"; }
D. @mixin debug($var) { content: "Type: #{inspect(type-of($var))}, Value: #{type-of(inspect($var))}"; }

Solution

  1. Step 1: Understand string interpolation in Sass

    Use #{} to insert function results inside strings.
  2. Step 2: Check each option's correctness

    @mixin debug($var) { content: "Type: #{type-of($var)}, Value: #{inspect($var)}"; } correctly calls type-of($var) and inspect($var) inside interpolation. @mixin debug($var) { content: "Type: type-of($var), Value: inspect($var)"; } treats functions as plain text. @mixin debug($var) { content: "Type: $var.type, Value: $var.inspect"; } uses invalid property access. @mixin debug($var) { content: "Type: #{inspect(type-of($var))}, Value: #{type-of(inspect($var))}"; } mixes function calls incorrectly.
  3. Final Answer:

    @mixin debug($var) { content: "Type: #{type-of($var)}, Value: #{inspect($var)}"; } -> Option C
  4. Quick Check:

    Use #{function()} for interpolation [OK]
Hint: Use #{ } to insert function results inside strings [OK]
Common Mistakes:
  • Not using interpolation for function calls
  • Trying to access functions as properties
  • Nesting functions incorrectly
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard