Logical assignments
The logical AND assignment (&&=) and the logical OR assignment (||=) operators short-circuit the respective binary logical operators.
Overview
The logical AND assignment (&&=) and the logical OR assignment (||=) operators short-circuit the respective binary logical operators.
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 85 | 85 | 79 | 14 | 85 | 14 | |
| Other | ||||||
| The logical OR assignment (||=) operator only evaluates the right operand and assigns to the left if the left operand is falsy. | 85 | 85 | 79 | 14 | 85 | 14 |
1+Supported (version) Not supported ※Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)
Syntax
JAVASCRIPT
let a = null;
a ??= 'default'; // a is 'default'
let b = '';
b ||= 'fallback'; // b is 'fallback'
let c = 'hello';
c &&= c.toUpperCase(); // c is 'HELLO' Live demo
Orassignment (||=)
variable that falsevalue(emptycharacter, 0 etc). And onlyassignment..
PreviewFullscreen
Nullcombinebodyassignment (??=)
variable that null is undefined. And onlyassignment..
PreviewFullscreen
Use cases
Using Logical assignments
The logical AND assignment (&&=) and the logical OR assignment (||=) operators short-circuit the respective binary logical operators.
Cautions
- No specific concerns. Stable across all major browsers.
Accessibility
- When updating the DOM dynamically, announce important changes to assistive technology with aria-live regions.
Related links
Powered by web-features