JavaScript ?? Nullish coalescing Operator
The nullish coalescing operator (??) returns the value on its right when the value on its left is null or undefined, and the left value otherwise. It is used to provide defaults.
Description
The nullish coalescing operator ?? returns its right-hand operand when its left-hand operand is null or undefined (a "nullish" value), and otherwise returns the left-hand operand. It is the standard way to give a default value.
It differs from the logical OR operator ||, which falls back for any falsy value. With ||, a valid value such as 0, '' or false is replaced by the default; with ??, it is kept. That makes ?? the safer choice for settings like a volume of 0 or an empty string.
The right-hand side is only evaluated when needed. You can't mix ?? directly with && or || without parentheses. The related assignment operator ??= assigns only when the variable is nullish.
Properties
- Operator
??- Category
- Logical
- Precedence
- 3 (1 is lowest, 18 is highest)
- Associativity
- left-to-right
Syntax
leftExpr ?? rightExprExample
Browser Support
The following information will show you the current browser support for the ?? operator. Hover over a browser icon to see the version that first introduced support for this operator.
Desktop





Tablets & Mobile





