# Truthy and Falsy

In Liquid, truthy and falsy values are essential for determining the outcome of conditional statements. This document provides an overview of what truthy and falsy values are and how they work in Coco templates.

## 1. Truthy Values

A truthy value is any value that evaluates to true in a conditional statement. In Liquid, all values are considered truthy except for those explicitly defined as falsy.

Examples of truthy values:

* Non-empty strings: `"hello"`
* Numbers other than zero: `42`
* Non-empty arrays: `[1, 2, 3]`
* Non-empty hashes: `{"key": "value"}`

Example usage:

```makefile
{% if product.name %}
  {{ product.name }}
{% endif %}
```

In this example, if `product.name` contains a non-empty string, it is considered truthy, and the title is displayed.

## 2. Falsy Values

A falsy value is any value that evaluates to false in a conditional statement. In Liquid, there are only two falsy values: `false` and `nil`.

Examples of falsy values:

* `false`: Represents a boolean false value.
* `nil`: Represents an undefined or empty value.

Example usage:

```arduino
{% if product.available %}
  In stock
{% else %}
  Out of stock
{% endif %}
```

In this example, if `product.available` is `false`, it is considered falsy, and "Out of stock" is displayed.

## 3. Coercion

When using non-boolean values in a conditional statement, Liquid will automatically coerce the value to its boolean equivalent. This means that truthy values will be treated as true and falsy values as false.

Example:

```css
cssCopy code{% if product.tags %}
  Tags: {{ product.tags | join: ', ' }}
{% endif %}
```

In this example, if `product.tags` is an empty array or `nil`, it is considered falsy, and the tags will not be displayed.

## Summary

Understanding truthy and falsy values in Liquid is essential for creating accurate and efficient conditional statements. By recognizing which values are considered truthy or falsy, you can control the flow of your templates and display content only when certain conditions are met. This helps in creating responsive and dynamic themes that adapt to various scenarios and data inputs.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cryptococo.gitbook.io/cocoshop-theme-development/liquid/basics/truthy-and-falsy.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
