Expressions
Expressions calculate values inside projections, function calls, and conditions.
Addition follows JavaScript
+ adds numbers or concatenates strings. For example, '3' + 2 produces '32', while '3' - 2 produces 1.
Arithmetic operators
| Operator | Operation |
|---|---|
+ | Addition or JavaScript string concatenation. |
- | Subtraction. |
* | Multiplication. |
/ | Division. |
unary - | Negation. |
select {
subtotal: price * quantity,
total: price * quantity + shipping,
refund: -amount
} from 'orders.json'
Precedence
JQL evaluates expressions in this order:
- Parentheses
- Unary minus
- Multiplication and division
- Addition and subtraction
select {
first: price + tax * quantity,
second: (price + tax) * quantity
} from 'orders.json'
Operators at the same level are evaluated from left to right.
Value conversion
Arithmetic follows JavaScript conversion rules. Subtraction, multiplication, division, and unary minus convert their operands with Number(...). Numeric strings can therefore participate in calculations.