In particular, the operator - given by
?? - will return the right-hand side if the left-hand expression resolves to
undefined, and otherwise returns the left-hand side.
const x = y ?? z;
In the example above,
z will be returned if
y is “nullish”, and otherwise
y will be returned.
Nullish coalescing is similar to (but stricter than) the more commonly-seen logical OR operator - given by
|| - which returns the result of the right-hand side expression if the left-hand side resolves to any falsy value, which includes nullish ones in addition to the boolean
false, empty string (