Flutter ● ○ ○ Dart 3.10

Kodebits Day 22: Null-Aware Operator

May 13 2026
The ?? operator returns its left operand if not null, otherwise its right.

What does this code output?

void main() {
  String? a = null;
  String? b = 'Hi';
  print(a ?? b ?? 'Bye');
}


Try it in the online Dart Playground →

[spoiler title="Solution"]

Answer:

Hi

Explanation:

The ?? operator chains left-to-right. a is null, so it checks b which is ‘Hi’.

[/spoiler]


Further Reading