Skip to content

Operators Reference

Complete reference for operators available in TinySystems expressions.

Arithmetic Operators

Addition (+)

Adds numbers or concatenates strings.

LeftRightResult
numbernumbernumber
stringstringstring
stringnumberstring

Examples:

{{5 + 3}}              // 8
{{'Hello ' + 'World'}} // "Hello World"
{{'Count: ' + $.num}}  // "Count: 42"

Subtraction (-)

Subtracts numbers.

LeftRightResult
numbernumbernumber

Examples:

{{10 - 4}}          // 6
{{$.total - $.tax}} // difference

Multiplication (*)

Multiplies numbers.

LeftRightResult
numbernumbernumber

Examples:

{{6 * 7}}                  // 42
{{$.price * $.quantity}}   // total
{{$.value * 0.1}}          // 10%

Division (/)

Divides numbers.

LeftRightResult
numbernumbernumber

Examples:

{{15 / 3}}           // 5
{{$.total / $.count}} // average
{{$.cents / 100}}     // dollars

Note: Division by zero returns infinity or NaN.


Modulo (%)

Returns remainder after division.

LeftRightResult
numbernumbernumber

Examples:

{{17 % 5}}       // 2
{{$.index % 2}}  // 0 or 1 (even/odd)
{{$.hour % 12}}  // 12-hour format

Comparison Operators

Equal (==)

Tests equality.

LeftRightResult
anyanyboolean

Examples:

{{$.status == 'active'}}  // true/false
{{$.count == 0}}          // true/false
{{$.a == $.b}}            // true/false

Type Coercion:

  • Compares by value
  • Different types may coerce

Not Equal (!=)

Tests inequality.

LeftRightResult
anyanyboolean

Examples:

{{$.status != 'deleted'}}  // true/false
{{$.count != 0}}           // true/false

Greater Than (>)

Tests if left is greater than right.

LeftRightResult
numbernumberboolean
stringstringboolean

Examples:

{{$.count > 100}}      // true/false
{{$.age > 18}}         // true/false
{{'b' > 'a'}}          // true (lexical)

Less Than (<)

Tests if left is less than right.

LeftRightResult
numbernumberboolean
stringstringboolean

Examples:

{{$.price < 50}}       // true/false
{{$.index < $.max}}    // true/false

Greater Than or Equal (>=)

Tests if left is greater than or equal to right.

LeftRightResult
numbernumberboolean
stringstringboolean

Examples:

{{$.age >= 18}}        // adult check
{{$.score >= 70}}      // passing grade

Less Than or Equal (<=)

Tests if left is less than or equal to right.

LeftRightResult
numbernumberboolean
stringstringboolean

Examples:

{{$.quantity <= $.max}}  // within limit
{{$.errors <= 0}}        // no errors

Logical Operators

Logical AND (&&)

Returns true if both operands are truthy.

LeftRightResult
anyanyboolean

Truth Table:

ABA && B
truetruetrue
truefalsefalse
falsetruefalse
falsefalsefalse

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.

LeftRightResult
anyanyboolean or value

Truth Table:

ABA || B
truetruetrue
truefalsetrue
falsetruetrue
falsefalsefalse

Short-Circuit / Default Value: If left is truthy, returns left value.

Examples:

{{$.premium || $.trial}}
{{$.name || 'Anonymous'}}       // default
{{$.count || 0}}                // default

Logical NOT (!)

Negates a boolean value.

OperandResult
truthyfalse
falsytrue

Examples:

{{!$.disabled}}      // is enabled
{{!$.error}}         // no error
{{!($.a > $.b)}}     // not greater

Conditional (Ternary) Operator

Syntax

condition ? valueIfTrue : valueIfFalse

Behavior

  1. Evaluates condition
  2. If truthy, returns valueIfTrue
  3. 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:

PrecedenceOperatorsAssociativity
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)

ValueTruthy/Falsy
truetruthy
falsefalsy
0falsy
non-zero numbertruthy
"" (empty string)falsy
non-empty stringtruthy
nullfalsy
objecttruthy
arraytruthy

To Number

ValueResult
"42"42
"3.14"3.14
true1
false0
"abc"NaN

To String

ValueResult
42"42"
true"true"
null"null"

Quick Reference

OperatorTypeExampleResult
+Arithmetic/String&#123;&#123;1 + 2&#125;&#125;3
-Arithmetic&#123;&#123;5 - 3&#125;&#125;2
*Arithmetic&#123;&#123;4 * 2&#125;&#125;8
/Arithmetic&#123;&#123;10 / 2&#125;&#125;5
%Arithmetic&#123;&#123;7 % 3&#125;&#125;1
==Comparison&#123;&#123;1 == 1&#125;&#125;true
!=Comparison&#123;&#123;1 != 2&#125;&#125;true
>Comparison&#123;&#123;2 > 1&#125;&#125;true
<Comparison&#123;&#123;1 < 2&#125;&#125;true
>=Comparison&#123;&#123;2 >= 2&#125;&#125;true
<=Comparison&#123;&#123;2 <= 2&#125;&#125;true
&&Logical&#123;&#123;true && true&#125;&#125;true
||Logical&#123;&#123;false || true&#125;&#125;true
!Logical&#123;&#123;!false&#125;&#125;true
? :Conditional&#123;&#123;true ? 'a' : 'b'&#125;&#125;"a"

Build flow-based applications on Kubernetes