← Back to Docs
Types
VDX supports four value types: int, float, string, and bool. You can optionally annotate variables with a type for runtime checking.
Value types
| Type | Example | Description |
|---|---|---|
int | 42 | Whole numbers |
float | 3.14 | Decimal numbers |
string | "hello" | Text |
bool | true / false | Boolean values |
Float literals
Any number with a decimal point is a float:
let pi = 3.14;
let half = 0.5;
let five = 5.0; // float, not int
print(pi); // 3.14Boolean literals
Use true and false directly:
let active = true;
let done = false;
if (active) {
print("active!");
}Type annotations
Add a type after the variable name with : to enable runtime type checking:
let count: int = 42;
let pi: float = 3.14;
let name: string = "VDX";
let ok: bool = true;Type annotations are optional. Without them, variables accept any value.
Type mismatch errors
If the value doesn't match the annotation, VDX throws a runtime error:
let x: int = "hello";
// error: Type mismatch: expected 'int', got 'string'The float annotation accepts both float and int values (widening).
Mixed arithmetic
When an int and float are used together in an operation, the result is automatically promoted to float:
print(10 + 3.5); // 13.5
print(2 * 3.14); // 6.28
print(7 / 2.0); // 3.5Truthiness
| Type | Truthy | Falsy |
|---|---|---|
| int | != 0 | 0 |
| float | != 0.0 | 0.0 |
| string | non-empty | "" |
| bool | true | false |
| array | non-empty | [] |
| object | always | — |
| void | — | always |