Exponentiation operator precedence
brendan.eich at gmail.com
Fri Sep 25 16:33:58 UTC 2015
Because C (B, BCPL, Algol). Too late to change JS where people do tricks
such as !-x. No win in risking compat break.
On Fri, Sep 25, 2015 at 4:18 AM Herby Vojčík <herby at mailbox.sk> wrote:
> Herby Vojčík wrote:
> > Claude Pache wrote:
> >> I just wonder why it is important that unary binds tighter? For
> >> instance, before I carefully studied the issue of this thread, I have
> >> never expected that unary minus binds tighter than binary multiplication
> >> operator in expressions like `-2*x` (although it does not matter in that
> >> case).
> >> Making the parentheses mandatory here will be somewhat annoying in
> >> perfectly reasonable expressions, where you usually don’t use
> >> parentheses in real math notation., like:
> >> ```
> >> let s2 = - x**2 - y**2 - z**2 + t**2
> >> ```
> > I would overcome it and do not write the parens:
> > let s2 = 0 - x**2 - y**2 - z**2 + t**2
> An off-topic thought: Unary minus (and plus) are only used with numbers
> in JS. Why are they treated specially, not as hidden 0+x and 0-x,
> respectively? That would be logical (unary plus and minus would have
> same precendence as binary plus and minus).
> > Writing mandatory parens here is ugly.
> > In fact, I am surprised "-2" is unary minus with 2, I thought it is
> > number -2. And similarly to Claude, I always read -x*y in math notation,
> > that is, as -(x*y). Luckily, for multiplication it does not matter.
> > Herby
> > _______________________________________________
> > es-discuss mailing list
> > es-discuss at mozilla.org
> > https://mail.mozilla.org/listinfo/es-discuss
> es-discuss mailing list
> es-discuss at mozilla.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss