logical-assignment operators

John Cowan cowan at ccil.org
Mon Feb 12 18:56:21 PST 2007

Brendan Eich scripsit:

> >Yes, but when $x is 0, it remains 0.
> Right -- but why would ES4 differ here?  ES1-3, any old JS in a  
> browser, would evaluate 'x = 0; x = x && x + 5; x' to result in 0  
> too. I did not follow why your original post made the null initial  
> value case (how about undefined?) special compared to 0, false, or ''.

Brain fart on my part (comes of knowing too many languages with imperfect
recall of the details).  Yes, that's flaky in any language where
zero is false, including Javascript.

> Sure, but ^^ can't short-circuit, it's not in C, and maybe we can do  
> without it. I've used (alpha == true) ^ ( bravo == true) and lived.

That works when alpha and bravo are booleans, but not when they are
richer values.  OTOH, if they are richer values, you probably still
want to keep track of which is which rather than just merging them.

Only do what only you can do.               John Cowan <cowan at ccil.org>
  --Edsger W. Dijkstra's advice
    to a student in search of a thesis

More information about the Es4-discuss mailing list