logical-assignment operators

liorean liorean at gmail.com
Tue Feb 13 17:49:38 PST 2007

On 13/02/07, Brendan Eich <brendan at mozilla.org> wrote:
> On Feb 13, 2007, at 6:14 AM, liorean wrote:
> > This is really a problem with using || and && as default and guard
> > operators. I've seen plenty code break because of || used as default
> > operator when the empty string or zero are meant to be legal values.
> Any code in public JS libraries come to mind?  I believe you, but
> I've never seen such bugs, and || for defaulting is popular in
> Mozilla-hosted JS.  (Here's where you promptly hit me with an lxr
> link to Moz code that abuses || ;-).

No, it's a too obvious bug for it to appear in any public libraries,
and those developers are too experienced to not see the problem
directly and fix it in the library right away, before making it

But I'm a member of several forums and mailing lists, and it's not an
uncommon error seen in code from newcomers to JavaScript that are
searching for an explanation why their code doesn't work, especially
if they don't have a programming background. but came from HTML/CSS
and graphic design directions.

> > Maybe adding this behaviour as new operators ||| and &&& with |||= and
> > &&&= assignment variants would be an idea?
> Inspired by === and !==, but please, let's not. The need for === is
> more acute in light of the non-equivalence-relation mess that is ==
> (useful mess? I have very mixed feelings, but just because its
> intransitive I think == is broken in JS -- and I'm to blame for it!
> When we were standardizing ES1, Guy Steele was more jaded; he noted
> that Common Lisp has something like five kinds of "equality"
> operators, so JS had a long way to go ;-)). Here, absent more
> evidence of misuse of || in the field, and without a clearer
> connotation for |||, I would be against adding any such operators.

One could alway argue that the full spectrum of
identity/equality/equivalency/similarity/convertability would make a
nicer programming environment, but on the other hand it can also add
confusion about which operator is the right one to use...
David "liorean" Andersson

More information about the Es4-discuss mailing list