Skip to main content
ZEN provides operators for arithmetic, comparison, logic, and data manipulation.

Arithmetic operators

Perform mathematical calculations on numbers.
OperatorNameExampleResult
+Addition5 + 38
-Subtraction10 - 46
*Multiplication6 * 742
/Division15 / 35
%Modulo (remainder)17 % 52
^Power2 ^ 101024

Operator precedence

Operations follow standard mathematical precedence:
  1. ^ (power)
  2. *, /, % (multiply, divide, modulo)
  3. +, - (add, subtract)
Use parentheses to control order:
(5 + 3) * 2    // 16, not 11
10 / (2 + 3)   // 2, not 7

Comparison operators

Compare values and return boolean results.
OperatorNameExampleResult
==Equal5 == 5true
!=Not equal5 != 3true
>Greater than10 > 5true
<Less than3 < 10true
>=Greater or equal5 >= 5true
<=Less or equal3 <= 5true

Logical operators

Combine boolean conditions.
OperatorNameExampleResult
andLogical ANDtrue and falsefalse
orLogical ORtrue or falsetrue
notLogical NOTnot truefalse

Short-circuit evaluation

Logical operators stop early when the result is determined:
false and expensiveFunction()   // Never calls the function
true or expensiveFunction()     // Never calls the function

Ternary operator

Conditionally return one of two values.
condition ? valueIfTrue : valueIfFalse
Examples:
age >= 18 ? "adult" : "minor"
score >= 70 ? "pass" : "fail"
stock > 0 ? "In Stock" : "Out of Stock"
Nested ternary:
score >= 90 ? "A" : score >= 80 ? "B" : score >= 70 ? "C" : "F"

Null coalescing operator

Return the first non-null value.
value ?? fallback
Examples:
user.nickname ?? user.name              // Use nickname, fall back to name
config.timeout ?? 30                    // Use config or default to 30
a ?? b ?? c ?? "default"                // Chain multiple fallbacks

Membership operators

Check if a value exists in a collection or range.

In operator

// Array membership
"US" in ["US", "CA", "GB"]              // true
5 in [1, 2, 3, 4, 5]                    // true

// Range membership (inclusive)
x in [1..10]                            // true if 1 <= x <= 10

// Range membership (exclusive)
x in (0..100)                           // true if 0 < x < 100

// Mixed brackets
x in [0..100)                           // true if 0 <= x < 100
x in (0..100]                           // true if 0 < x <= 100

Not in operator

Negate membership tests:
status not in ["deleted", "archived"]
x not in [0..100]

String operators

Concatenation

The + operator joins strings:
"Hello" + " " + "World"                 // "Hello World"
"Order #" + string(orderId)             // "Order #12345"
firstName + " " + lastName              // "John Doe"

Template strings

Embed expressions in strings:
`Hello, ${name}!`
`Total: ${round(total, 2)}`
`Items: ${len(items)}`

Array operators

Index access

items[0]                                // First item
items[len(items) - 1]                 // Last item
items[-1]                               // Last item (negative index)

Object operators

Property access

user.name                               // Dot notation
user["name"]                            // Bracket notation
user[fieldName]                         // Dynamic key

Optional chaining

Access nested properties is optional:
user.address.city    // Returns null if any part is null

Operator precedence table

From highest to lowest precedence:
PrecedenceOperators
1() (grouping)
2., [] (property access)
3+, - (unary)
4?? (null coalescing)
5^ (power, right-associative)
6*, /, %
7not (unary)
8+, - (binary)
9==, !=, <, >, <=, >=, in, not in
10and
11or
12? : (ternary)