Operator Precedence
When a filter expression contains more than one type of operator, the operator precedence determines the order that the components of the overall expression will be evaluated in.
The above filter expression contains 3 types of operators.
- The + and - are additive operators and are evaluated first.
- The > and < are comparison operators and are evaluated second.
- The && operator is a logical operator and is evaluated last.
In the image above, the colored rectangles group the components of the filter expression in the order that they will be evaluated in. Parentheses can be used to group expressions that are components of larger expressions, in much the same way the colored rectangles are used to illustrate the operator precedence.
(Venus.Latitude > (Mars.Latitude - 1)) && (Venus.Latitude < (Mars.Latitude + 1))
Expressions contained within the innermost parantheses are evaluated first and so on until the resulting expression within the outermost parantheses is evaluated. The parantheses in the above filter expression are not required because the order of evaluation is the same as the default order of evaluation that is controlled by the operator precedence.
When writing a filter expression, if you are ever unsure of the order that the components will be evaluated in, then you can use parantheses to guarentee that the expression will evaluate as intended.