Power operator, why does -2**3 throws?

Cyril Auburtin cyril.auburtin at gmail.com
Fri Oct 14 11:43:02 UTC 2016


What does it change if it handles floats?

I just checked
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence

unary + is 16, while exponentiation is 15, so the opposite order that I
thought

2016-10-14 13:37 GMT+02:00 J Decker <d3ck0r at gmail.com>:

> probably because it's floating point native not integer like you'd think,
> so -2.00000001 ** 3 is hard?
>
> On Fri, Oct 14, 2016 at 4:30 AM, Cyril Auburtin <cyril.auburtin at gmail.com>
> wrote:
>
>> I would expect `-2**3` to return -8, or `-2**2 == -4`, since it should be
>> like `-(2**3)`
>>
>> Firefox gives a clearer error then Chrome with:
>> > SyntaxError: unparenthesized unary expression can't appear on the
>> left-hand side of '**'
>>
>> Is there a reason for this restriction? Python does it `-2**3` fine
>>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20161014/4fbb33dc/attachment-0001.html>


More information about the es-discuss mailing list