Javascript Operator Priority Specifics

I find it difficult to understand what is meant by a combination of Exponentiation and everything else (multiplication, division, etc.) in group 14 of Javascript priority.

Source - MDN

Three questions:

  • What is the meaning of combining associative law from right to left and left to right in one group?
  • How can you rephrase the expression 2 ** 3 * 4 in accordance with these rules and still get the same answer? 4 * 2 ** 3 works ... what does it mean?
  • When / how is this not equivalent to a seemingly simpler assignment of a higher degree of exponentiation?
+7
javascript
source share
1 answer

1) 2 ** 3 ** 4 , being associative from right to left, is 2 ** (3 ** 4) . 2 / 3 / 4 , being an associative connection from left to right, (2 / 3) / 4 .

2/3) I believe that 2 ** 3 * 4 is (2 ** 3) * 4 . 2 * 3 ** 4 2 * (3 ** 4) (as rated by es6fiddle ).

This does not follow from the table; but exponentiation must take precedence over multiplication. Mixing from left to right and from right to left in the same ranking ranking is strange. In fact, as far as I could see in ES7 drawings , it is not processed at all grammatically in the same way as * , / and % , but as a unary operation (!).

Also note that not a single engine other than Babel and Traceur currently supports ** , so it is currently mostly academic. MDN is a wiki, and the exponentiation operator has been added by Mozillian; but AFAIK, since Mozilla does not currently support ** , does not actually document the way Mozilla is interpreted.

+2
source share

All Articles