Arithmetic Operators
Numeric Operations
| Operator | Description |
|---|---|
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division |
% | Modulo (remainder) |
All arithmetic operators except + require both operands to be numbers.
var sum = 10 + 5 # 15
var diff = 10 - 3 # 7
var product = 4 * 5 # 20
var quotient = 10 / 3 # 3.333...
var remainder = 10 % 3 # 1
String Concatenation
The + operator also performs string concatenation. If either operand is a string, the other operand is automatically converted to its string representation:
var msg = "Count: " + 42 # "Count: 42"
var label = "active: " + true # "active: true"
Division and Modulo by Zero
Division or modulo by zero throws a runtime error. Always validate the divisor:
if divisor != 0 then
Data.result = value / divisor
end
Unary Negation
The - prefix operator negates a numeric value:
var x = 5
var y = -x # -5