Operators Reference
Complete reference for operators available in TinySystems expressions.
Arithmetic Operators
Addition (+)
Adds numbers or concatenates strings.
| Left | Right | Result |
|---|---|---|
| number | number | number |
| string | string | string |
| string | number | string |
Examples:
{{5 + 3}} // 8
{{'Hello ' + 'World'}} // "Hello World"
{{'Count: ' + $.num}} // "Count: 42"Subtraction (-)
Subtracts numbers.
| Left | Right | Result |
|---|---|---|
| number | number | number |
Examples:
{{10 - 4}} // 6
{{$.total - $.tax}} // differenceMultiplication (*)
Multiplies numbers.
| Left | Right | Result |
|---|---|---|
| number | number | number |
Examples:
{{6 * 7}} // 42
{{$.price * $.quantity}} // total
{{$.value * 0.1}} // 10%Division (/)
Divides numbers.
| Left | Right | Result |
|---|---|---|
| number | number | number |
Examples:
{{15 / 3}} // 5
{{$.total / $.count}} // average
{{$.cents / 100}} // dollarsNote: Division by zero returns infinity or NaN.
Modulo (%)
Returns remainder after division.
| Left | Right | Result |
|---|---|---|
| number | number | number |
Examples:
{{17 % 5}} // 2
{{$.index % 2}} // 0 or 1 (even/odd)
{{$.hour % 12}} // 12-hour formatComparison Operators
Equal (==)
Tests equality.
| Left | Right | Result |
|---|---|---|
| any | any | boolean |
Examples:
{{$.status == 'active'}} // true/false
{{$.count == 0}} // true/false
{{$.a == $.b}} // true/falseType Coercion:
- Compares by value
- Different types may coerce
Not Equal (!=)
Tests inequality.
| Left | Right | Result |
|---|---|---|
| any | any | boolean |
Examples:
{{$.status != 'deleted'}} // true/false
{{$.count != 0}} // true/falseGreater Than (>)
Tests if left is greater than right.
| Left | Right | Result |
|---|---|---|
| number | number | boolean |
| string | string | boolean |
Examples:
{{$.count > 100}} // true/false
{{$.age > 18}} // true/false
{{'b' > 'a'}} // true (lexical)Less Than (<)
Tests if left is less than right.
| Left | Right | Result |
|---|---|---|
| number | number | boolean |
| string | string | boolean |
Examples:
{{$.price < 50}} // true/false
{{$.index < $.max}} // true/falseGreater Than or Equal (>=)
Tests if left is greater than or equal to right.
| Left | Right | Result |
|---|---|---|
| number | number | boolean |
| string | string | boolean |
Examples:
{{$.age >= 18}} // adult check
{{$.score >= 70}} // passing gradeLess Than or Equal (<=)
Tests if left is less than or equal to right.
| Left | Right | Result |
|---|---|---|
| number | number | boolean |
| string | string | boolean |
Examples:
{{$.quantity <= $.max}} // within limit
{{$.errors <= 0}} // no errorsLogical Operators
Logical AND (&&)
Returns true if both operands are truthy.
| Left | Right | Result |
|---|---|---|
| any | any | boolean |
Truth Table:
| A | B | A && B |
|---|---|---|
| true | true | true |
| true | false | false |
| false | true | false |
| false | false | false |
Short-Circuit: If left is false, right is not evaluated.
Examples:
{{$.active && $.verified}}
{{$.count > 0 && $.enabled}}
{{$.user != null && $.user.admin}}Logical OR (||)
Returns true if either operand is truthy.
| Left | Right | Result |
|---|---|---|
| any | any | boolean or value |
Truth Table:
| A | B | A || B |
|---|---|---|
| true | true | true |
| true | false | true |
| false | true | true |
| false | false | false |
Short-Circuit / Default Value: If left is truthy, returns left value.
Examples:
{{$.premium || $.trial}}
{{$.name || 'Anonymous'}} // default
{{$.count || 0}} // defaultLogical NOT (!)
Negates a boolean value.
| Operand | Result |
|---|---|
| truthy | false |
| falsy | true |
Examples:
{{!$.disabled}} // is enabled
{{!$.error}} // no error
{{!($.a > $.b)}} // not greaterConditional (Ternary) Operator
Syntax
condition ? valueIfTrue : valueIfFalseBehavior
- Evaluates condition
- If truthy, returns valueIfTrue
- If falsy, returns valueIfFalse
Examples:
{{$.active ? 'Yes' : 'No'}}
{{$.count > 0 ? $.count : 0}}
{{$.type == 'admin' ? 'full' : 'limited'}}Nested Ternary
{{$.score >= 90 ? 'A' : ($.score >= 80 ? 'B' : 'C')}}Recommendation: Use sparingly; complex logic is hard to read.
Operator Precedence
From highest (evaluated first) to lowest:
| Precedence | Operators | Associativity |
|---|---|---|
| 1 | () | - |
| 2 | ! | Right |
| 3 | *, /, % | Left |
| 4 | +, - | Left |
| 5 | >, <, >=, <= | Left |
| 6 | ==, != | Left |
| 7 | && | Left |
| 8 | || | Left |
| 9 | ? : | Right |
Examples
// * before +
{{2 + 3 * 4}} // 14, not 20
// && before ||
{{a || b && c}} // a || (b && c)
// Comparison before logical
{{$.a > 1 && $.b < 2}} // ($.a > 1) && ($.b < 2)
// Use parentheses for clarity
{{($.a + $.b) * $.c}}
{{($.x || $.y) && $.z}}Type Coercion
To Boolean (Truthiness)
| Value | Truthy/Falsy |
|---|---|
true | truthy |
false | falsy |
0 | falsy |
| non-zero number | truthy |
"" (empty string) | falsy |
| non-empty string | truthy |
null | falsy |
| object | truthy |
| array | truthy |
To Number
| Value | Result |
|---|---|
"42" | 42 |
"3.14" | 3.14 |
true | 1 |
false | 0 |
"abc" | NaN |
To String
| Value | Result |
|---|---|
42 | "42" |
true | "true" |
null | "null" |
Quick Reference
| Operator | Type | Example | Result |
|---|---|---|---|
+ | Arithmetic/String | {{1 + 2}} | 3 |
- | Arithmetic | {{5 - 3}} | 2 |
* | Arithmetic | {{4 * 2}} | 8 |
/ | Arithmetic | {{10 / 2}} | 5 |
% | Arithmetic | {{7 % 3}} | 1 |
== | Comparison | {{1 == 1}} | true |
!= | Comparison | {{1 != 2}} | true |
> | Comparison | {{2 > 1}} | true |
< | Comparison | {{1 < 2}} | true |
>= | Comparison | {{2 >= 2}} | true |
<= | Comparison | {{2 <= 2}} | true |
&& | Logical | {{true && true}} | true |
|| | Logical | {{false || true}} | true |
! | Logical | {{!false}} | true |
? : | Conditional | {{true ? 'a' : 'b'}} | "a" |