This operators are using for assign value to variable is it's null or we want to apply any other arithmetic operation in single variable.
Here, Below I have write all the Assignment operators and their description.
Operator Symbol | Operator Name | Operator Description |
\= | Equal to | Use to assign values to the expression or variable |
??= | Assignment operator | Assign the value only if it is null. |
+= | Add and Assignment | Add value in variable (Same as a = a + 10) |
-= | Subtract and Assignment | Subtract value in variable (Same as a = a - 10 |
*= | Multiply and Assignment | Multiply value in variable (Same as a = a * 10 |
/= | Divide and Assignment | Divide value in variable (Same as a = a / 10 |
void main()
{
var a;
a??= 20;
print("Checking null $a"); // get value as 20 due to a value is not declare before
a+= 20;
print("Add value $a");
a-= 20;
print("Sub value $a");
a*= 20;
print("Multi Value $a");
}
/**
Output:
Checking null 20
Add value 40
Sub value 20
Multi Value 400
**/
ย