Yes I like syntactic sugar when it doesn't sacrifice clarity (e.g. class, arrow functions).
However, I do like the logical assignment operator pointed out by Jordan somewhat more than the "conditional assign" ("if not assigned") idea at the beginning of this thread. My reason is that you cannot "reset" a variable to a "not assigned" state to re-use the "conditional assign" operator, whereas you can reset a variable to a nullish or falsy state and re-use the logical assignment operator, e.g. x ||= 5; x = null; //this works as a reset! x ?= 5; x = undefined; //this doesn't work as a reset! Apparently nothing will However, maybe non-resettability is a desired feature of the conditional assign operator idea, so maybe it should be an additional feature, albeit with different syntax On Mon, 13 Apr 2020 at 18:02, Bergi <a.d.be...@web.de> wrote: > Hi! > > > What I've long wanted is an assignment operator which evaluates to the > > pre-assignment value of the LHS. > > You know, sort of like `a++` evaluates to the pre-incremented value of > `a`. > > Given the amount of confusion that the difference between `++a`, `a++` > (and `a += 1`) already has caused, I doubt that would be a good idea. > In most, if not all, cases the desired behaviour can be easier and > cleaner expressed with two statements, and a temporary variable if > absolutely necessary. > > > ``` > > let a = 1; > > console.log(a =^= 2); // logs 1 and then sets a to 2 > > ``` > > would be just > ``` > let a = 1; > console.log(a) > a = 2; > ``` > > kind regards, > Bergi > _______________________________________________ > es-discuss mailing list > es-discuss@mozilla.org > https://mail.mozilla.org/listinfo/es-discuss >
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss