Favorites

JavaScript ??= Nullish coalescing assignment Operator

☕
Enjoying this site?

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

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

The nullish coalescing assignment operator (??=) assigns a value to a variable only if the variable is null or undefined.

Description

The nullish coalescing assignment operator x ??= y assigns y to x only when x is null or undefined. Other falsy values, such as 0 and '', are kept. It's the safest way to fill in missing defaults, and to create something on first use: cache[key] ??= [].

It short-circuits like the other logical assignments: the right-hand side is only evaluated, and the assignment only happens, when the current value is nullish. That makes obj.list ??= [] a concise way to create a property on first use and then reuse it, as in grouping items into arrays.

It's especially useful for function options, filling in defaults for missing settings without overwriting legitimate values such as 0, false or an empty string. Default parameters, function f(size = 10), only replace undefined, so ??= is handy when null should be replaced too.

Properties

Operator
??=
Category
Assignment
Precedence
2 (1 is lowest, 18 is highest)
Associativity
right-to-left

Syntax

x ??= y

Example

const options = { volume: 0 };
options.volume ??= 50;
options.theme ??= 'dark';
console.log(options);

const groups = {};
(groups.red ??= []).push('apple');
console.log(groups);

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