Today I learned that javascript gained a nullish coalescing operator (??
) in ECMAScript 2020.
const result = potentialEmpty ?? fallbackValue;
It return the right operand if the left operand is null or undefined so for me this is a convenient alternative to using the OR (||
) operator if I don’t want the fallbackValue on falsy values like 0
or an empty string.