The ?? operator returns its right-hand operand when the left-hand operand is null or undefined.
Called the nullish coalescing operator, ?? provides a compact way to supply a fallback only when a value is absent. For example, userName ?? "Guest" produces "Guest" if userName is null or undefined; otherwise, it preserves userName. The operator short-circuits, so the right-hand expression is evaluated only when needed.
The most important distinction is between ?? and the logical OR operator, ||. OR treats every falsy value—including 0, false, NaN, and the empty string—as a reason to use its fallback. Nullish coalescing treats only null and undefined as missing, making it safer for defaults such as a numeric zero or an intentionally empty label.
The operator was standardized in ECMAScript 2020, the language standard’s 11th edition. It should not be confused with ??=, introduced with logical assignment operators in ECMAScript 2021. The latter assigns a fallback to a variable only when that variable is nullish.