3 ms·
Those logical assignment operators look pretty neat. I wish they went into detail about how they work and how to use them, though.
by reidjs 6y ago
Those logical assignment operators look pretty neat. I wish they went into detail about how they work and how to use them, though.
- richyliu 6y agoHere'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.
- joemaller1 6y agoMight save a few keystrokes here and there: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_AND_assignment https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR_assignment https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR_assignment https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- z3t4 6y agoCould be used for ubfuscation