Logical AND assignment short-circuits, meaning that x &&= y
is equivalent to x && (x = y)
, except that the expression x
is only evaluated once.
No assignment is performed if the left-hand side is not truthy, due to short-circuiting of the logical AND operator. For example, the following does not throw an error, despite x
being const
:
Neither would the following trigger the setter:
const x = {
get value() {
return 0;
},
set value(v) {
console.log("Setter called");
},
};
x.value &&= 2;
In fact, if x
is not truthy, y
is not evaluated at all.
const x = 0;
x &&= console.log("y evaluated");
// Logs nothing
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4