JavaScript &&= Logical AND assignment Operator
The logical AND assignment operator (&&=) assigns a value to a variable only if the variable is currently truthy.
Description
The logical AND assignment operator x &&= y assigns y to x only if x is truthy. If x is falsy, nothing is assigned and y isn't even evaluated. It's short for x && (x = y), and is useful for updating a value only when it exists.
Because it short-circuits, the right-hand side is only evaluated when the assignment actually happens, so any function call or side effect there is skipped when the variable is falsy. And unlike x = x && y, it doesn't perform an assignment at all when x is falsy, which matters for setters and read-only properties.
Common uses include transforming a value only if it's present, such as trimming an optional string, and clearing a related value when a condition is met. The three logical assignment operators, &&=, ||= and ??=, were added to JavaScript together in 2021.
Properties
- Operator
&&=- Category
- Assignment
- Precedence
- 2 (1 is lowest, 18 is highest)
- Associativity
- right-to-left
Syntax
x &&= yExample
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





