Does Dart's ?? operator short-circuit?
To check this, I decided to create a small example. Here’s the function I used.
int? show(int x, [bool isNull = false]) {
print(x);
return isNull ? null : x;
}
When we run the following
show(10) ?? show(11);
it prints
10
Now let’s try with a null
value
show(10, true) ?? show(11);
which prints
10
11
This means that Dart uses short-circuiting for ??
operator!