You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 22, 2020. It is now read-only.
Anecdotally, I have experience with CoffeeScript, which has all the flavors of logical assignment operator.
I don't think I ever used &&=, and I don't recall seeing it used often.
On the other hand, ??= (which is spelled ?= in CoffeeScript) was commonly useful, and does seem to me (if we're taking votes) worth the complexity it would add to JavaScript.
The other point I want to make is that I recall seeing ||= used often, but it usually seemed like ?= would have been a slightly better choice in most of those cases. I got the sense that ||= was used due to familiarity with the javascript idiom of using || as a default operator, and the programmer just didn't know about ?=.
Have we considered just adding ??= and not the others? You could argue for consistency, but it's my opinion that &&= is not very useful, and that ||= is an attractive nuisance, which people will reach for reflexively and will use to write code that is in some cases incorrect.
There is quite a lot of JS code out there containing subtle bugs caused by treating || as the default operator, and don't the same caveats apply to ||= as apply to using || as a default operator?
The text was updated successfully, but these errors were encountered:
There is quite a lot of JS code out there containing subtle bugs caused by treating || as the default operator, and don't the same caveats apply to ||= as apply to using || as a default operator?
I think that learning and teaching the difference between || and ?? is a better strategy than attempting to force clueless coders to write bugfree code in spite of themselves. Or, taking a more pessimistic POV, I think that people not understanding the difference between ||= and ??= are likely to write buggy code anyway.
An important point is that we introduce ??= not later than ||=, so that people will have no good reason to use the latter when they mean the former.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Thanks for this proposal.
Anecdotally, I have experience with CoffeeScript, which has all the flavors of logical assignment operator.
I don't think I ever used
&&=
, and I don't recall seeing it used often.On the other hand,
??=
(which is spelled?=
in CoffeeScript) was commonly useful, and does seem to me (if we're taking votes) worth the complexity it would add to JavaScript.The other point I want to make is that I recall seeing
||=
used often, but it usually seemed like?=
would have been a slightly better choice in most of those cases. I got the sense that||=
was used due to familiarity with the javascript idiom of using||
as a default operator, and the programmer just didn't know about?=
.Have we considered just adding
??=
and not the others? You could argue for consistency, but it's my opinion that&&=
is not very useful, and that||=
is an attractive nuisance, which people will reach for reflexively and will use to write code that is in some cases incorrect.There is quite a lot of JS code out there containing subtle bugs caused by treating
||
as the default operator, and don't the same caveats apply to||=
as apply to using||
as a default operator?The text was updated successfully, but these errors were encountered: