Skip to main content
The ??= operator is a null-aware compound assignment operator in Dart. It evaluates the left-hand operand and assigns the value of the right-hand expression to it strictly if the left-hand operand evaluates to null. As an expression, the operation yields the final value of the left-hand operand, allowing it to be used inline within larger expressions.

Evaluation Mechanics

  1. Expression Yield: Because ??= is an expression rather than a statement, it evaluates to a value. This distinguishes it from an if (x == null) { x = y; } block, which is a statement that yields no value.
int? x; print(x ??= 5); // Assigns 5 to x, evaluates to 5, and prints 5
Non-Null Operand Bypass:
Short-Circuit Execution:
Tired of Poor Dart Skills? Fix That With Deep Grasping!Learn More