---
title: "Data Types"
description: "Scalar types, complex types, type checking operators, and type casting."
canonical_url: "https://www.zeyos.com/zymba/zymba-guide/language-basics/types"
markdown_url: "https://www.zeyos.com/ai/guide/zymba/zymba-guide/language-basics/types.md"
section: "zymba-guide"
authority: "draft-guide"
language: "en"
source_repository: "zeyos/guide"
source_path: "docs/zymba/02-language-basics/types.md"
source_revision: "cce886a8da98cd124ee3644711085bbdcf1a87ce"
---

# Data Types

## Scalar types

### Integer

Whole numbers without decimal points:

```zymba
$count    = 42;
$negative = -10;
$zero     = 0;
```

### Float

Numbers with decimal points:

```zymba
$price    = 19.99;
$pi       = 3.14159;
$negative = -5.5;
```

### String

Text values. Zymba supports three string delimiter styles:

```zymba
$single    = 'Hello';        // Single quotes — no interpolation
$double    = "World";        // Double quotes — supports $variable interpolation
$multiline = `Line 1
Line 2
Line 3`;                      // Backtick strings — multiline, supports interpolation
```

Backtick strings are commonly used for SQL queries and multiline text:

```zymba
$sql = `SELECT name, price
    FROM items
    WHERE status = 1
    ORDER BY name`;
```

### Boolean

```zymba
$isActive   = true;
$isDisabled = false;
```

### Null

Represents the absence of a value:

```zymba
$empty = null;
```

## Complex types

### Arrays

Ordered collections of values with optional string keys:

```zymba
// Indexed array
$numbers = [1, 2, 3, 4, 5];

// Associative array (object-like)
$person = [name: "John", age: 30];

// Empty array
$empty = [];
```

### Objects

Objects created with `new object()` or from a class:

```zymba
$person = new object() {
    name = "John";
    age  = 30;
};
```

## Type checking

### The `is` operator

```zymba
$num = 42;
$str = "hello";
$arr = [1, 2, 3];

if ($num is numeric) { }  // true for int and float
if ($str is string) { }   // true
if ($arr is object) { }   // true — arrays are objects in Zymba
```

Available type checks:

| Check | Description |
|-------|-------------|
| `is numeric` | Integer or float |
| `is int` | Integer only |
| `is float` | Float only |
| `is string` | String type |
| `is bool` | Boolean type |
| `is object` | Array or object |
| `is null` | Null value |
| `is function` | Function or closure |

### The `typeof` operator

Returns the type name as a string:

```zymba
echo typeof 42;            // "int"
echo typeof 3.14;          // "float"
echo typeof "hello";       // "string"
echo typeof [1, 2];        // "object"
echo typeof null;          // "null"
echo typeof function() {}; // "function"
```

### The `exists` and `empty` operators

Check whether a variable or key exists, or whether a value is empty:

```zymba
$name = "John";

if (exists $name) { }   // true — variable is defined and not null

if (empty $name) { }    // false — non-empty string

$blank = "";
if (empty $blank) { }   // true — empty string is empty
```

### The `count` operator

Returns the character count of a string or the element count of an array:

```zymba
$str = "hello";
echo count $str;    // 5

$arr = [1, 2, 3];
echo count $arr;    // 3
```

## Type casting

Explicitly convert between types:

```zymba
$num      = 42;
$floatNum = (float) $num;   // 42.0
$strNum   = (string) $num;  // "42"

$price      = "19.99";
$priceFloat = (float) $price; // 19.99
```

Available casts:

| Cast | Description |
|------|-------------|
| `(int)` | Convert to integer (truncates decimals) |
| `(float)` | Convert to float |
| `(string)` | Convert to string |
| `(bool)` | Convert to boolean |

You can also use unary `+` to coerce a value to a number:

```zymba
$amount = +"42.50";  // 42.5 (float)
```

## Truthiness rules

Values that are considered **falsy** in Zymba:

- `false`
- `0` (integer zero)
- `0.0` (float zero)
- `""` (empty string)
- `"0"` (the string "0")
- `null`

Everything else is **truthy**, including empty arrays `[]`:

```zymba
if ([]) {
    echo "empty array is truthy"; // This DOES execute
}
if (0) {
    // This block does NOT execute — 0 is falsy
}
if ("0") {
    // This block does NOT execute — "0" is falsy
}
```

:::warning
`"0"` is falsy in Zymba. Check explicitly when you need to distinguish between `null`, `""`, and `"0"`.
:::
