Sass Introspection Functions

Sass Introspection Functions
Sass Introspection Functions are used to inspect variables and values—to find out what type they are, whether they exist, and how they behave.
They are extremely useful in advanced Sass, mixins, functions, and framework-level logic.
💡 Think of introspection as “asking Sass questions about data”.
🔹 Why Use Introspection Functions?
They help you:
Write flexible & reusable mixins
Prevent errors
Handle different data types dynamically
Build robust Sass libraries
🔹 Common Sass Introspection Functions
1️⃣ type-of()
Returns the type of a value.
✔ Output:
Other outputs:
stringcolorlistmapboolnull
2️⃣ unit()
Returns the unit of a number.
✔ Output:
3️⃣ unitless()
Checks if a number has no unit.
✔ Output:
4️⃣ comparable()
Checks if two numbers can be compared.
✔ Output:
5️⃣ variable-exists()
Checks if a variable exists.
✔ Output:
6️⃣ global-variable-exists()
Checks for a global variable.
7️⃣ function-exists()
Checks if a function exists.
✔ Output:
8️⃣ mixin-exists()
Checks if a mixin exists.
9️⃣ feature-exists()
Checks if a Sass feature is supported.
🔟 call()
Calls a function dynamically.
✔ Output:
🔹 Practical Example (Safe Mixin)
🔹 Dynamic Function Call Example
❗ Important Notes
✔ Mainly for advanced Sass users
✔ Helpful for writing defensive code
✔ Makes mixins flexible and safe
✔ Overuse can make code complex
📌 Summary
Introspection inspects data types & existence
Essential for advanced mixins/functions
Helps prevent errors
Used heavily in Sass frameworks
