Favorites

JavaScript ||= Logical OR 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 logical OR assignment operator (||=) assigns a value to a variable only if the variable is currently falsy.

Description

The logical OR assignment operator x ||= y assigns y only if x is falsy. It's commonly used to set defaults, but because 0, '' and false are falsy, those valid values get replaced too. If you only want to replace null and undefined, use ??=.

Like the other logical assignment operators, it short-circuits: when the variable already has a truthy value, the right-hand side isn't evaluated and no assignment is made. That makes it a convenient way to fill in a value lazily, such as cache.data ||= computeData(), where the expensive function only runs the first time.

The equivalent long form is x || (x = y), not x = x || y; the difference is that no assignment happens when x is truthy, which matters for setters and frozen objects. Choose ||= when every falsy value should be replaced, and ??= when only missing values should.

Properties

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

Syntax

x ||= y

Example

const settings = { title: '', retries: 0 };
settings.title ||= 'Untitled';
settings.retries ||= 3;
console.log(settings);

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