what does ?? in dart mean code example

Example 1: dart null aware operator ??

print(1 ?? 3); // <-- Prints 1.
print(null ?? 12); // <-- Prints 12.

int a; // The initial value of a is null.
a ??= 3;
print(a); // <-- Prints 3.

a ??= 5;
print(a); // <-- Still prints 3.

Example 2: dart ?? operator

int val1;
final int val2 = 20;

console.log(val1 ?? val2); //result => 20 because val1 is null

----------------------------------

final int val1 = 30;
final int val2 = 20;

console.log(val1 ?? val2); //result => 30 because val1 is not null

Tags:

Dart Example