content icon indicating copy to clipboard operation
content copied to clipboard

Grouping operator has other uses

Open GarrettS opened this issue 3 years ago • 3 comments

MDN URL

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Grouping

What specific section or headline is this issue about?

The Grouping Operator

What information was incorrect, unhelpful, or incomplete?

"The grouping operator ( ) controls the precedence of evaluation in expressions."

What did you expect to see?

The Grouping Operator groups primary expressions.

This can be useful for managing operator precedence, but that's not what it does.

It can also be used to avoid ASI pitfalls and to force tokens' evaluation as PrimaryExpressions.

(function a() {
    return 1;
}) () // <-- FE, not FD

It can be used to avoid ASI pitfalls:

function b() {
    return 
        "LongStringWithManyCharacters"
     + " even more chars";
}

— and it can be accidentally interpreted as Arguments when following an Expression, to interpret a CallExpression.

Do you have any supporting links, references, or citations?

http://jibbering.com/faq/notes/code-guidelines/asi.html

Do you have anything more you want to share?

It seems like MDN quality has decreased. I'm disappointed. I don't have endless time to volunteer for its betterment, however.

GarrettS avatar Oct 26 '22 23:10 GarrettS

It seems like MDN quality has decreased. I'm disappointed.

I don't understand where that sentiment comes from, since we've never removed any information. Still, I think the suggestion makes sense.

Josh-Cena avatar Oct 26 '22 23:10 Josh-Cena

Well, parseInt is gone, for example. Ditto for eval, encodeURIComponent, etc.

https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Functions/parseInt

Function parseInt changed behavior, too. It originally attempted to parse strings with leading 0's as octal.

GarrettS avatar Oct 27 '22 17:10 GarrettS

What you are looking for are at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent; you may use the search.

We rigorously document implementation reality—we don't control how they should behave. parseInt doesn't automatically treat numbers as octal, so we document that it doesn't. Historical behavior is no longer relevant to developers today, and there are established processes at MDN to remove outdated behavior notes.

Josh-Cena avatar Oct 27 '22 17:10 Josh-Cena