0

context : the starting point is a simple question i asked myself : why typeof '' === typeof "" === typeof `` is false ? Shortly after, i found the answer but that lead me to the subject of precedence and associativity.

MDN gives us the table : precedence order (here) and associativity for JavaScript. But i'm not sur on which source MDN based his table. So i started to search : firstly i read the specification from ECMA website, but did not find any reference to associativity or precedence. (ES 8, Javascript 1.0 (it's a pdf))

So i search on StackOverflow for answered questions and found some but most of all are pointing to MDN table. One of those questions lead me to esdiscuss but again, can't find the source of what define the associativity and precedence of an operator precisely.

So i'm here to cary on my research :

Question : Is precedence and associativity defined in the ES standard or related to the implementation (Node, ff, chrome etc)? In the case of it is a standard, can you point me the spot i missed ? In the case that it is related to the implementation, what defined the order of precedence ?

thanks.

  • It looks like precedence are beeing discussed in the TC39 github issues (https://github.com/search?q=org%3Atc39+precedence&type=Issues) so it should be a global behavior defined in the specs. – Seblor Aug 22 '18 at 12:27
  • The standards are rather hard to read. They are not written as specifications like the C standard which would allow one to understand a language feature. Rather, the standards for ECMAscript is written from the point of view of telling someone how they can implement an interpreter. – slebetman Aug 22 '18 at 14:27

1 Answers1

0

Yes, operator precedence and associativity is governed by the ECMAScript specification. It is not spelled out in a table like MDN does it, but rather an implicit property of the grammar (how the productions are nested).

Bergi
  • 630,263
  • 148
  • 957
  • 1,375