The ??
operator returns the right-hand operand if the left-hand operand is null
or undefined
. It is useful for providing default values.
Example:
const value = null;
console.log(value ?? 'default'); // Output: 'default'
const number = 0;
console.log(number ?? 42); // Output: 0
Tags: basic, JavaScript, Operators