---
title: "Null and Undefined"
description: "The difference between null, undefined, and empty string in iXML."
canonical_url: "https://www.zeyos.com/ixml/ixml-guide/data-types/null-and-undefined"
markdown_url: "https://www.zeyos.com/ai/guide/ixml/ixml-guide/data-types/null-and-undefined.md"
section: "ixml-guide"
authority: "guide"
language: "en"
source_repository: "zeyos/guide"
source_path: "docs/ixml/02-data-types/null-and-undefined.md"
source_revision: "cce886a8da98cd124ee3644711085bbdcf1a87ce"
---

# Null and Undefined

iXML distinguishes between three "empty" states that are often confused:

| State | typeof | Meaning |
|-------|--------|---------|
| **Undefined** | `'undefined'` | Variable has never been declared — it has neither type nor value |
| **Null** | `'null'` | Variable is defined but holds no data |
| **Empty string** | `'string'` | Variable is defined and holds a string with zero length |

## Null

The **NULL** type represents a variable that has been defined but holds no data. Set a variable to null explicitly with the [`null`](https://www.zeyos.com/ixml/ref/null) command:

```xml
<null var="x" />
<typeof var="x" var_result="t" />
<output>$t</output>
<!-- null -->
```

NULL is the typical result when a database lookup returns no rows or when an optional value is absent.

## Undefined

An **undefined** variable has never been assigned any value. It has neither type nor value:

```xml
<typeof var="neverSet" var_result="t" />
<output>$t</output>
<!-- undefined -->
```

You can make a defined variable undefined again with [`unset`](https://www.zeyos.com/ixml/ref/unset):

```xml
<set var="x">hello</set>
<unset var="x" />
<typeof var="x" var_result="t" />
<output>$t</output>
<!-- undefined -->
```

## Comparison behavior

In loose comparison, `undefined`, `NULL`, `FALSE`, and `''` (empty string) all compare equal to each other:

```xml
<if value1="$undefined_var" func="=" value2="">
    <output>undefined equals empty string</output>
</if>
<!-- undefined equals empty string -->
```

This means you cannot distinguish between these states using `<if>` alone. Use [`typeof`](https://www.zeyos.com/ixml/ref/typeof) for precise type checking:

```xml
<typeof var="x" var_result="t" />
<if value1="$t" func="=" value2="null">
    <output>x is explicitly null</output>
</if>
```

## Neutral literal behavior

When an uninitialized (undefined) variable is used in a typed context, it defaults to the **neutral literal** of that type:

- In arithmetic context: `0`
- In string context: `''`
- In boolean context: `FALSE`

This allows operations on uninitialized variables without errors, but can mask bugs if you expect a variable to have been set.
