4 ms·
This is not ambiguous, because that supposed ambiguity is used to prevent some combination of operators appearing without parentheses. Mathematically speaking t
by lifthrasiir 3y ago
This is not ambiguous, because that supposed ambiguity is used to prevent some combination of operators appearing without parentheses. Mathematically speaking the JS precedence relation is a partial order, unlike many other languages using a total order. I believe JS has made a correct choice here and a partially ordered precedence should be used more.
- paulddraper 3y agoIt is ambiguous (albeit deliberately so), therefore parens are required. If don't believe I've used that word wrong. That's precisely the language quoted in the article for JavaScriptCore/Safari: SyntaxError: parentheses must be used to disambiguate
- reanimus 3y agoAmbiguous is definitely correct. The precedence is ambiguous, but the language chooses to make that ambiguity illegal. In some languages it might fall under the realm of "undefined behavior" (in that it compiles/validates syntactically but will likely blow up at runtime), though most linters for even those languages warn you about that. Alternatively, it might define a precedence for you, avoiding the need for parens.
- lifthrasiir 3y agoFor what it's worth, the current title of this submission is "JavaScript has multiple (ambiguous) operator precedence chains", which is made up by the submitter. I question the use of a word "ambiguous" here, because it really sounds like that JS somehow had two precedence chains and had to resolve them. Absolutely not. But it's correct that the programmer intent would be indeed ambiguous, hence that error message.