Dart Operators : Assignment

Dart Operators : Assignment

ยท

1 min read

  • 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 SymbolOperator NameOperator Description
\=Equal toUse to assign values to the expression or variable
??=Assignment operatorAssign the value only if it is null.
+=Add and AssignmentAdd value in variable (Same as a = a + 10)
-=Subtract and AssignmentSubtract value in variable (Same as a = a - 10
*=Multiply and AssignmentMultiply value in variable (Same as a = a * 10
/=Divide and AssignmentDivide 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

**/
ย