??) is a binary operator that evaluates to the value of its left-hand operand if it is not null; otherwise, it evaluates and returns the right-hand operand.
Syntax
Evaluation Logic
The operator follows a strict evaluation order with short-circuiting behavior:- Evaluate Left Operand:
expression1is evaluated. - Null Check:
- If
expression1is non-null, the operation resolves immediately to the value ofexpression1.expression2is not evaluated. - If
expression1is null,expression2is evaluated, and its result becomes the result of the operation.
- If
Short-Circuiting
Because the operator short-circuits, any side effects (such as function calls, I/O, or variable mutations) contained within the right-hand operand will only occur if the left-hand operand isnull.
Examples
Basic EvaluationStatic Type Analysis
- Left Operand: Should be of a nullable type. If the static type of the left operand is non-nullable, the operator is redundant, and the Dart analyzer will issue a warning.
- Return Type: The static type of the expression
a ?? bis the least upper bound (LUB) of the type ofa(promoted to non-nullable) and the type ofb.
Master Dart with Deep Grasping Methodology!Learn More





