Assignment Operators
on Saturday, 18th of July, 2020
Assigning a value to a variable in Dart is done by using the = operator.
var name = "PJ"; Dart also supports compound operators, which are the equivalent of performing an operation and assignment.
| Operator | Meaning |
|---|---|
| -= | subtraction assignment |
| /= | divisions assigment |
| %= | modulo assignment |
| += | addition assignment |
| *= | multiplication |
| ~/= | integer division assignment |
| >>= | bitwise shift right assignment |
| ^= | bitwise XOR assignment |
| <<= | bitwise shift left assignment |
| &= | bitwise and assignment |
| |= | bitwise or assignment |
example:
a -= b;
// above is shorthand for
a = a - b;
// *= example
var a = 2; // Assign using =
a *= 3; // Assign and multiply: a = a * 3
assert(a == 6);- next: Comments