Nullish Coalescing Operator (??)
??) and is used to provide a default value for a variable if the variable is
undefined, but not for other falsy values such as
false, or an empty string (
The nullish coalescing (
??) operator is a logical operator that returns its right-hand side operand when its left-hand side operand is null or
undefined, and otherwise returns its left-hand side operand.
// Using the nullish coalescing operator let variable1 = null; let variable2 = "Hello"; let result1 = variable1 ?? "Default Value"; let result2 = variable2 ?? "Default Value"; console.log(result1); // Output: Default Value console.log(result2); // Output: Hello