Member-only story

Concise Code: Meet the New Logical Assignment Operators in JavaScript

Cameron Manavian
Level Up Coding
Published in
3 min readJul 28, 2020

--

The three new logical operators: nullish, AND, and OR are now available

Choices, choices: blissful ignorance || unpleasant truth

Want to write less code?

Let’s meet the new assignment operators available in JavaScript, which are readily available and in Firefox 79, and Chrome 85 (not available in Node.js quite yet).

The logical assignment operator proposal specifies new logical operators to help quickly write cleaner assignment JavaScript code.

There’s the QQ equals (logical nullish assignment), the And And Equals (logical AND assignment), and the Or Or Equals (logical OR assignment), each offering a better way to update and assign values using shorthand convenience operators.

The new operators have the same short circuit behavior of the existing common logical operations that are already implemented, such as plus equals (+= a.k.a addition assignment) and all of the other useful compound assignment operators that JavaScript has to offer.

I think these new operators are extremely useful because they allow for a handy way to change assignments only when certain logical conditions are met.

We don’t get unwanted side effects, just simple coalescing of values into variables with quick…

--

--

No responses yet

Write a response