Favorites

JavaScript ?? Nullish coalescing Operator

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
??
JavaScript Logical OperatorThis operator is supported by all modern browsers.
Updated 28th November 2026

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 ?? rightExpr

Example

const settings = { volume: 0, title: '' };

console.log(settings.volume ?? 50);   // keeps 0
console.log(settings.volume || 50);   // replaces 0
console.log(settings.title ?? 'Untitled');
console.log(settings.theme ?? 'light');

let count = null;
count ??= 10;
console.log(count);

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.

This operator is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee