Expressions
Expressions let you write dynamic logic — calculations, comparisons, and string manipulation.
What Are Expressions?
Expressions are mini-formulas that compute values:
var.balance + 100 → adds 100 to balance
user.first_name + " Smith" → combines strings
var.age >= 18 → checks if adult
Where to Use Expressions
Expressions work in:
| Place | Example |
|---|---|
| Condition nodes | var.balance > 0 |
| Transform nodes | value * 2 |
| Text templates | {{var.balance + 10}} |
| Validation | value >= 18 && value <= 100 |
Basic Math
| Operation | Symbol | Example | Result |
|---|---|---|---|
| Add | + | 5 + 3 | 8 |
| Subtract | - | 10 - 4 | 6 |
| Multiply | * | 6 * 7 | 42 |
| Divide | / | 20 / 4 | 5 |
| Remainder | % | 17 % 5 | 2 |
Comparisons
| Comparison | Symbol | Example | Result |
|---|---|---|---|
| Equals | == | 5 == 5 | true |
| Not equals | != | 5 != 3 | true |
| Greater than | > | 10 > 5 | true |
| Less than | < | 3 < 5 | true |
| Greater or equal | >= | 5 >= 5 | true |
| Less or equal | <= | 4 <= 5 | true |
Logic (And/Or/Not)
| Operation | Symbol | Example | Result |
|---|---|---|---|
| And | && | true && false | false |
| Or | || | true || false | true |
| Not | ! | !true | false |
Combining Conditions
var.age >= 18 && var.is_verified
Both must be true.
var.role == "admin" || var.role == "moderator"
Either can be true.
Working with Text
Combining Strings
"Hello, " + user.first_name + "!"
→ "Hello, Alice!"
Useful Functions
| Function | What It Does | Example |
|---|---|---|
len(x) | Length | len("hello") → 5 |
upper(x) | Uppercase | upper("hello") → "HELLO" |
lower(x) | Lowercase | lower("HELLO") → "hello" |
trim(x) | Remove whitespace | trim(" hi ") → "hi" |
contains(x, y) | Has substring? | contains("hello", "ell") → true |
Working with Numbers
| Function | What It Does | Example |
|---|---|---|
int(x) | Convert to integer | int("42") → 42 |
float(x) | Convert to decimal | float("3.14") → 3.14 |
abs(x) | Absolute value | abs(-5) → 5 |
min(a, b) | Smaller value | min(5, 3) → 3 |
max(a, b) | Larger value | max(5, 3) → 5 |
Working with Lists
| Function | What It Does | Example |
|---|---|---|
len(arr) | Count items | len([1,2,3]) → 3 |
first(arr) | First item | first([1,2,3]) → 1 |
last(arr) | Last item | last([1,2,3]) → 3 |
join(arr, sep) | Combine to string | join(["a","b"], "-") → "a-b" |
The Ternary Operator
A quick if/else in one line:
condition ? value_if_true : value_if_false
Examples:
var.age >= 18 ? "Adult" : "Minor"
var.balance > 0 ? var.balance : 0
Template Expressions
Inside text, use {{...}}:
Hello {{user.first_name}}!
Your balance: ${{var.balance}}
Status: {{var.is_active ? "Active" : "Inactive"}}
Common Patterns
Calculate Discount
var.total * (1 - var.discount_rate)
Format Currency
"$" + string(var.balance)
Check Empty
var.email != "" && var.email != nil
Safe Division
var.count > 0 ? var.total / var.count : 0
Tips
Start Simple
Get basic expressions working first, then add complexity.
Test Your Logic
Use a Send Message node to show expression results during development:
Debug: {{var.age >= 18}}
Type Matters
"5" (text) is different from 5 (number). Use int() or float() to convert.
Quick Reference
Common Checks
| Purpose | Expression |
|---|---|
| Is registered? | var.registered == true |
| Has balance? | var.balance > 0 |
| Is admin? | user.id == 12345 |
| Text not empty? | len(var.name) > 0 |
| Contains word? | contains(input, "help") |
Next Steps
- Variables → — Store expression results
- Logic Nodes → — Use expressions in conditions