# Types

Liquid objects can have one of six types.

Liquid objects can have one of six types. You can initialize Liquid variables with the [assign](https://developer.versacommerce.de/articles/liquid-tags-variable-tags#assign) or [capture](https://developer.versacommerce.de/articles/liquid-tags-variable-tags#capture) tags.

## String

Strings are declared by wrapping the value of a variable in single or double quotes.

```liquid
{% assign my_string = "Hello World!" %}
```

## Number

Numbers include floats and integers.

```liquid
{% assign my_int = 25 %}
{% assign my_float = 39.756 %}
```

## Boolean

Booleans are either `true` or `false`. No quotes are needed when you declare a Boolean.

```liquid
{% assign foo = true %}
{% assign bar = false %}
```

## Nil

Nil is a special empty value that is returned when Liquid code has no result. It is **not** a string with the characters "nil".

Nil counts as false in the conditions of `if` blocks and other Liquid tags that check whether a statement is true.

In this example, Liquid does not output the text if there is no tracking number (`fulfillment.tracking_numbers` returns `nil`):

```liquid
{% if fulfillment.tracking_numbers %}
  There is a tracking number.
{% endif %}
```

Tags or outputs that return `nil` print nothing on the page.

```liquid
Tracking number: {{ fulfillment.tracking_numbers }}
```

```text
Tracking number:
```

## Array

Arrays hold lists of variables of any type.

## Accessing items in arrays

To access all items in an array, loop through it with a [for](https://developer.versacommerce.de/articles/liquid-tags-iteration-tags#for) or [tablerow](https://developer.versacommerce.de/articles/liquid-tags-iteration-tags#tablerow) tag.

```liquid
{% for tag in product.tags %}
  {{ tag }}
{% endfor %}
```

```text
sale summer spring wholesale
```

## Accessing specific items in arrays

Use square brackets `[` `]` to access a specific item in an array. Array indexes start at zero.

```liquid
<!-- if product.tags = "sale", "spring", "summer", "wholesale" -->
{{ product.tags[0] }}
{{ product.tags[1] }}
{{ product.tags[2] }}
```

```text
sale
spring
summer
```

## Initializing arrays

You cannot initialize arrays with Liquid alone.

You can, however, use the [split filter](https://developer.versacommerce.de/articles/liquid-filters-string-filters#split) to break a single string into an array of substrings.

## EmptyDrop

An EmptyDrop object is returned when you try to access a deleted object (for example a page or a post) by its [handle](https://developer.versacommerce.de/articles/liquid-basics-handle). In this example, `page_1`, `page_2` and `page_3` are all EmptyDrop objects.

```liquid
{% assign variable = "hello" %}
{% assign page_1 = pages[variable] %}
{% assign page_2 = pages["does-not-exist"] %}
{% assign page_3 = pages.this-handle-does-not-exist %}
```

## Checking for emptiness

You can check whether an object exists before you access one of its attributes.

```liquid
{% unless pages.about == empty %}
  <!-- Only printed if the page with the handle "about" is not empty -->
  <h1>{{ pages.about.title }}</h1>

  <div>
    {{ pages.about.content }}
  </div>
{% endunless %}
```

If you do not check for emptiness first, Liquid can output empty HTML elements:

```html
<h1></h1>

 <div></div>
```

You can check collections for emptiness, too:

```liquid
{% unless collections.frontpage == empty %}
  {% for product in collections.frontpage.products %}
    {% include "product-grid-item" %}
  {% else %}
    <p>We have a "frontpage" collection, but it's empty.</p>
  {% endfor %}
{% endunless %}
```

## EmptyDrop attributes

EmptyDrop objects have only one attribute, `empty?`, which is always *true*.

*Existing* collections and pages have no `empty?` attribute. Their `empty?` is falsy, so calling it inside an `if` statement returns *false*. In an `unless` statement on existing collections and pages, `empty?` returns `true`.

To check whether a drop is empty, do not use `empty?`. [Use a condition](#checking-for-emptiness) that compares the drop with `empty`.
