Nullish Coalescing Operator
Nullish Coalescing Operator
The Nullish Coalescing Operator (??) is a JavaScript operator introduced in ECMAScript 2020 that provides a concise way to handle nullish values.
It allows you to check if a value is null or undefined and provide a default value if it is.
Unlike the logical OR operator (||), which considers falsy values such as an empty string or zero as "falsey" and falls back to the default value, the Nullish Coalescing Operator only checks for null or undefined values.
This operator is particularly useful when you want to assign a default value to a variable only if it is null or undefined, ensuring that other falsy values are not overwritten.
For example, const result = value ?? defaultValue;
assigns defaultValue to result only if value is null or undefined.