Order of operations, also called operator precedence, is a set of rules specifying which procedures should be performed first in a mathematical expression.
Precedence Overview
Note
- Highest precedence means highest priority
- Associativity is (then) done from left to right, for example
3 + 5 + 8will be processed as((3 + 5) + 8)
| Precedence | Type of Operator | Examples |
|---|---|---|
| 11 | Nular operators (commands with no arguments): - commandName |
- Variables - Values - () / [] / {} / "" / '' -enclosed expressions |
| 10 | Unary operators (commands with 1 argument): - commandName a |
* +a - -a - +array - ! b - not b |
| 9 | Hash-select operator | - array # index |
| 8 | Power operator | - a ^ b |
| 7 | - Number multiplication, division and remainder - atan2 - Config access (/) |
* a * b - a / b - a % b - a mod b - a / b - a atan2 b |
| 6 | - Number addition and subtraction - Array addition and subtraction - String addition - min and max commands |
* a + b - a - b - arr1 + arr2 - arr1 - arr2 - str1 + str2 - a min b - a max b |
| 5 | - else (if-then-else structure) | N/A |
| 4 | Binary operators (commands with 2 arguments): - a commandName b |
- setDir - switch colon (:) |
| 3 | - == and != comparisons - Number comparisons - Config access (>>) |
- a == b - a != b - a > b - a < b - a >= b - a <= b - config >> name |
| 2 | Logical and operator | - && - and |
| 1 | Logical or operator | - || - or |