Operators
Dart defines the operators shown in the following table.You can override many of these operators, as described inOverridable operators.
| Description | Operator |
|---|---|
| unary postfix | expr++ expr— () [] . ?. |
| unary prefix | -expr !expr ~expr ++expr —expr await expr |
| multiplicative | / % ~/ |
| additive | + - |
| shift | << >> >>> |
| bitwise AND | & |
| bitwise XOR | ^ |
| bitwise OR | | |
| relational and type test | >= > <= < as is is! |
| equality | == != |
| logical AND | && |
| logical OR | || |
| if null | ?? |
| conditional | expr1 ? expr2 : expr3 |
| cascade | .. |
| assignment | = = /= += -= &= ^= etc. |
Warning: Operator precedence is an approximation of the behavior of a Dart parser. For definitive answers, consult the grammar in the Dart language specification.
When you use operators, you create expressions. Here are some examplesof operator expressions:
1. a++
2. a + b
3. a = b
4. a == b
5. c ? a : b
6. a is T
In the operator table,each operator has higher precedence than the operators in the rowsthat follow it. For example, the multiplicative operator % has higherprecedence than (and thus executes before) the equality operator ==,which has higher precedence than the logical AND operator &&. Thatprecedence means that the following two lines of code execute the sameway:
1. // Parentheses improve readability.
2. if ((n % i == 0) && (d % i == 0)) ...
4. // Harder to read, but equivalent.
5. if (n % i == 0 && d % i == 0) ...
Warning: For operators that work on two operands, the leftmost operand determines which version of the operator is used. For example, if you have a Vector object and a Point object, aVector + aPoint uses the Vector version of +.
