Assignment Operators

This class of operators contain those operators which are used to assign value to the operands. It goes like this: 

Operator SymbolOperator NameOperator Description
=Equal toUse to assign values to the expression or variable
??=Assignment operatorAssign the value only if it is null.

Example: Using Assignment Operators in the program 

Dart
void main()
{
    int a = 5;
    int b = 7;

    // Assigning value to variable c
    var c = a * b;
  
    print("assignment  operator used c = a*b so now c = $c\n");

    // Assigning value to variable d
    var d;
  
      // Value is assign as it is null
    d ??= a + b;
  
    print("Assigning value only if d is null");
    print("d??= a+b so d = $d \n");
    
    // Again trying to assign value to d
    d ??= a - b;
      // Value is not assign as it is not null
  
    print("Assigning value only if d is null");
    print("d??= a-b so d = $d");
    print("As d was not null value was not updated");
}

Output: 

assignment  operator used c = a*b so now c = 35

Assigning value only if d is null
d??= a+b so d = 12

Assigning value only if d is null
d??= a-b so d = 12
As d was not null value was not updated

Compound Assignment Operator

Apart from there is another way where we can use a operator that is compound assignment operator where we combine an operator with an assignment operatorso to shorten the steps and make code more effective.

Example:

a+=1;

// The above statement is same as
// the statement mentioned below
a=a+1;

Operators in Dart

The operators are special symbols that are used to carry out certain operations on the operands. The Dart has numerous built-in operators which can be used to carry out different functions, for example, ‘+’ is used to add two operands. Operators are meant to carry operations on one or two operands. 

Similar Reads

Precedence Table of Operators in Dart

Description Operator Associativity unary postfix expr++ expr– () [] ?[] . ?. ! None unary prefix -expr !expr ~expr ++expr –expr await expr None multiplicative * / % ~/ Left additive + – Left shift << >> >>> Left bitwise AND & Left bitwise XOR ^ Left bitwise OR | Left relational and type test >= > <= < as is is! None equailty == != None logical AND && Left logical OR || Left if-null ?? Left conditional expr ? expr2 : expr3 Right cascade .. ?.. Left assignment = *= /= += -= &= ^= etc. Right...

Different types of operators in Dart

The following are the various types of operators in Dart:...

1. Arithmetic Operators

This class of operators contain those operators which are used to perform arithmetic operation on the operands. They are binary operators i.e they act on two operands. They go like this:...

2. Relational Operators

This class of operators contain those operators which are used to perform relational operation on the operands. It goes like this:...

3. Type Test Operators

This class of operators contain those operators which are used to perform comparison on the operands. It goes like this:...

4. Bitwise Operators

This class of operators contain those operators which are used to perform bitwise operation on the operands. It goes like this:...

5. Assignment Operators

This class of operators contain those operators which are used to assign value to the operands. It goes like this:...

6. Logical Operators

This class of operators contain those operators which are used to logically combine two or more conditions of the operands. It goes like this:...

7. Conditional Operators

This class of operators contain those operators which are used to perform comparison on the operands. It goes like this:...

8. Cascade Notation Operators:

This class of operators allows you to perform a sequence of operation on the same element. It allows you to perform multiple methods on the same object. It goes like this:...

Contact Us