Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary commas in the JavaScript function statements #28147

Closed
wants to merge 2 commits into from

Conversation

kkpan11
Copy link

@kkpan11 kkpan11 commented Jul 24, 2023

The comma at the end of the last line in the JavaScript code snippet is not required and can be removed.

Description

In JavaScript, commas are used to separate elements in lists or objects. However, when there is no element after the last one in a list, it's not necessary to include a trailing comma. The code is perfectly valid and correct without the comma at the end of the expression.

Motivation

  • Improve readability by removing unnecessary comma

@kkpan11 kkpan11 requested a review from a team as a code owner July 24, 2023 10:42
@kkpan11 kkpan11 requested review from hamishwillee and removed request for a team July 24, 2023 10:42
@github-actions github-actions bot added the Content:Games Games docs label Jul 24, 2023
@kkpan11 kkpan11 changed the title Remove unused comma in the JavaScript function statements Remove unnecessary comma in the JavaScript function statements Jul 24, 2023
@kkpan11 kkpan11 changed the title Remove unnecessary comma in the JavaScript function statements Remove unnecessary commas in the JavaScript function statements Jul 24, 2023
Copy link
Member

@Josh-Cena Josh-Cena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, code on MDN is automatically formatted and there's no point in hand-formatting them. Trailing commas are considered a good habit in engineering because when you add extra arguments the diff is cleaner

@Josh-Cena Josh-Cena closed this Jul 24, 2023
@kkpan11
Copy link
Author

kkpan11 commented Jul 24, 2023

@Josh-Cena Thanks for the description. :)
So, even in the math statements like the following, right?

a +
b +
c +
d +
e,

@Josh-Cena
Copy link
Member

The point is, the expression here is an argument to a function.

f(
  a +
    b +
    c,
);

@kkpan11
Copy link
Author

kkpan11 commented Jul 24, 2023

@Josh-Cena Ah, I got the point that you are talking about.
But I look at the JavaScript source and check the documentation from MDN about Math.sqrt().
The Math.sqrt() function only takes 1 parameter not the arbitrary number of arguments.
My opinion is if the function only takes 1 parameter, shall we add the unmeaningful comma in the pure math statements instead of simple function call?

const distance = Math.sqrt(
    (point.x - sphere.x) * (point.x - sphere.x) +
      (point.y - sphere.y) * (point.y - sphere.y) +
      (point.z - sphere.z) * (point.z - sphere.z),
);

const distance = Math.sqrt(
    (point.x - sphere.x) * (point.x - sphere.x) +
    (point.y - sphere.y) * (point.y - sphere.y) +
    (point.z - sphere.z) * (point.z - sphere.z)
);

Or am I misunderstanding something?

Thanks for the kind clarification, Josh. 👍

@Josh-Cena
Copy link
Member

This is purely a formatting concern. You shouldn't add extra semantics to formatting—it only complicates authoring because you have to make a conscious choice about whether you should add a comma in every place. Again, all of our formatting is automated so we can forget about these decisions altogether.

@kkpan11
Copy link
Author

kkpan11 commented Jul 24, 2023

@Josh-Cena Got it, thanks for the clarifying. That's true about formatting automatically in the collaborative large documents.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:Games Games docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants