Skip to main content
Version: v5.0

Operators

tip

In the examples a, b and c can be replaced with custom variables, module variables, number literals or any other expression. They are only used here for brevity.

Arithmetic operators

OperatorSyntaxExample
Additiona + b2 + 3 is 5
Subtractiona - b5 - 2 is 3
Multiplicationa * b4 * 3 is 12
Divisiona / b10 / 4 is 2.5
Exponentiationa ** b2 ** 3 is 8
Modulusa % b7 % 3 is 1 (remainder)
warning

The arithmetic operators always treat both sides as numbers. In particular, + cannot be used to join strings'a' + 'b' gives NaN. Use a template string or the concat function to join text.

Comparison operators

OperatorSyntaxExample
Equality (loose)a == b5 == '5' is true
Equality (strict)a === b5 === '5' is false
Inequality (loose)a != b5 != '5' is false
Inequality (strict)a !== b5 !== '5' is true
Greater thana > b5 > 3 is true
Greater than or equala >= b5 >= 5 is true
Less thana < b3 < 5 is true
Less than or equala <= b5 <= 3 is false

Loose equality (==) considers values equal if they match after type conversion, so a variable holding the text '5' equals the number 5. Strict equality (===) requires the types to match too. When comparing a variable against a value, loose equality is usually what you want, as variables from some connections are provided as text.

The ordering operators (>, >=, <, <=) convert both sides to numbers before comparing — they cannot be used to compare text alphabetically.

Logical operators

OperatorSyntaxExample
Logical ANDa && btrue && false is false
Logical ORa || b0 || 'fallback' is 'fallback'
Nullish coalescinga ?? bundefined ?? 'fallback' is 'fallback'
Logical NOT!a!true is false

|| falls back to the right side whenever the left side is falsy (including 0 and empty strings), while ?? only falls back when the left side is undefined or null. Use ?? to provide a default for a variable that may not be set:

$(custom:operator_name) ?? 'No operator'

Ternary operator

The conditional (ternary) operator picks between two values:

OperatorSyntaxExample
Conditionala ? b : c$(custom:on_air) ? 'LIVE' : 'READY'

Unary operators

OperatorSyntaxExample
Negation-a-(2 + 3) is -5
Convert to number+a+'5' is the number 5
Logical NOT!a!0 is true
Bitwise NOT~a~5 is -6

Bitwise operators

OperatorSyntaxExample
Bitwise ANDa & b6 & 3 is 2
Bitwise ORa | b6 | 3 is 7
Bitwise XORa ^ b6 ^ 3 is 5
Right shifta >> b8 >> 2 is 2
Left shifta << b2 << 2 is 8

Expression grouping

Parentheses group sub-expressions to control the order of evaluation:

(a + b) * c

Operator precedence follows the usual JavaScript rules, but when combining several operators it is clearer to add parentheses than to rely on precedence.

Objects and arrays

OperationSyntax
Define an object{ a: 1 }
Define an array[1, 2]
Object/array lookup$(my:var)['some-prop'] or $(my:var)[0]
Property access (dot)$(my:var).some_prop

Assignment of temporary variables

Within multi-line expressions, intermediate results can be stored in temporary variables:

OperatorSyntax
Assignmenta = 1
Addition assignmenta += 1
Subtraction assignmenta -= 1
Multiplication assignmenta *= 2
Division assignmenta /= 2
Modulus assignmenta %= 2
Exponent assignmenta **= 2
Incrementa++ or ++a
Decrementa-- or --a
Logical OR assignmenta ||= 1
Logical AND assignmenta &&= 1
Nullish coalescing assignmenta ??= 1
Left shift assignmenta <<= 1
Right shift assignmenta >>= 1
Bitwise XOR assignmenta ^= 1
Bitwise AND assignmenta &= 1
Bitwise OR assignmenta |= 1

For example, this accumulates a value across a few lines and returns the result:

total = $(custom:a)
total += $(custom:b)
total /= 2
total