2 ms·
Here's more information on the 3 new logical assignments Logical OR assignment (||=) [1] Logical AND assignment (&&=) [2] Logical nullish assignment (??=) [3]
by richyliu 6y ago
Here's more information on the 3 new logical assignments
Logical OR assignment (||=) [1]
Logical AND assignment (&&=) [2]
Logical nullish assignment (??=) [3]
An example for OR assignment:
let a = '';
a ||= 'hello';
console.log(a); // prints 'hello'
a ||= 'not this';
console.log(a); // prints 'hello'
[1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR_assignment https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
[2]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_AND_assignment https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
[3]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_nullish_assignment https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- gosukiwi 6y agoFinally. I missed that idiom from Ruby so much.