I am writing a program that has math in it.
According to Mozilla, **
is for exponentiation, and it has lower priority than unary minus (-
). Therefore, I would expect -1**2
to mean (-1)**2
. However, Firefox says:
Uncaught SyntaxError: unparenthesized unary expression can't appear on the left-hand side of '**'
The Mozilla page says nothing about requiring parentheses between math operators when the documented operator precedence is desired. So why does -1**2
not work?
I understand that the JavaScript precedence is not the same as what Mathematicians use. However, that is not grounds for forcing parentheses that are not required by the specification. The current behavior seems to mean that code written according to the specification might not work?