I was reading mdn docs about operator precedence and operator associativity "operator precedence and operator associativity(MDN)" and wanted to know more about it reading the ECMAScript specification.
But i didn't find anything about operator precedence and operator associativity in there.
Can someone guide me with a link to the ECMAScript specification where they describe precedence and associativity of each operator.
Any help is really appreciated. And i need to know if the ECMAScript specification doesn't mention anything about
precedence and associativity of each operator how language implementers know which operator to resolve first before the other i mean how they know which operator should get evaluated before the other operator
As an example, the operator predescendence of multiplication over addition is in section 12.8 of the specification
12.8 Additive Operators Syntax
AdditiveExpression: MultiplicativeExpression AdditiveExpression + MultiplicativeExpression AdditiveExpression - MultiplicativeExpression
edited for readability
Because of these productions 1 + 2 * 3 gets produced through an AdditiveExpression, with two MultiplicativeExpressions inside:
AdditiveExpression
(AdditiveExpression + MultiplicativeExpression)
((MultiplicativeExpression) + (MultiplicativeExpression MultiplicativeOperator MultiplicativeExpression))
//...
((1) + (2 * 3))
If you evaluate this, the MultiplicativeExpressions get evaluated first (see section 12.8.3.1).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With