sass-site/source/_includes/doc_snippets/truthiness-and-falsiness.liquid

24 lines
942 B
Plaintext
Raw Normal View History

{% markdown %}
2023-05-30 23:23:34 +02:00
## Truthiness and Falsiness
2023-05-30 23:23:34 +02:00
Anywhere `true` or `false` are allowed, you can use other values as well. The
values `false` and [`null`][] are *falsey*, which means Sass considers them to
indicate falsehood and cause conditions to fail. Every other value is considered
*truthy*, so Sass considers them to work like `true` and cause conditions to
succeed.
2023-05-30 23:23:34 +02:00
[`null`]: /documentation/values/null
2023-05-30 23:23:34 +02:00
For example, if you want to check if a string contains a space, you can just
write `string.index($string, " ")`. The [`string.index()` function][] returns
`null` if the string isn't found and a number otherwise.
2023-05-30 23:23:34 +02:00
[`string.index()` function]: /documentation/modules/string#index
2023-05-30 22:27:01 +02:00
{% endmarkdown %}
{% headsUp %}
2023-05-30 23:23:34 +02:00
Some languages consider more values falsey than just `false` and `null`. Sass
isn't one of those languages! Empty strings, empty lists, and the number `0` are
all truthy in Sass.
{% endheadsUp %}