In ES2020, what operator is denoted by ?? and handles null/undefined?
Answer
nullish coalescing operator
Answer
nullish coalescing operator
In ES2020, the ?? operator is the nullish coalescing operator, returning a fallback only when its left side is null or undefined.
For example, `const name = input ?? "Guest"` uses `"Guest"` when `input` is missing or explicitly set to null. Unlike the older logical OR operator, ?? preserves valid falsy values such as 0, false, and an empty string.
The operator became part of ECMAScript's 11th edition, published in June 2020. It is short-circuiting: JavaScript evaluates the right-hand expression only when the left-hand value is nullish. This makes it useful for defaults without accidentally replacing meaningful zeroes or blank text.
A common mix-up is confusing ?? with ??=, which is a nullish-assignment operator that updates a variable, or with ?., optional chaining, which safely accesses a property or method. JavaScript also disallows mixing ?? directly with || or && without parentheses, avoiding unclear precedence.
Source: Wikipedia · fact-checked Aug. 2026