-
Notifications
You must be signed in to change notification settings - Fork 22.5k
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
Conversation
JavaScript
function statementsJavaScript
function statements
JavaScript
function statementsJavaScript
function statements
There was a problem hiding this 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 Thanks for the description. :) a +
b +
c +
d +
e, |
The point is, the expression here is an argument to a function. f(
a +
b +
c,
); |
@Josh-Cena Ah, I got the point that you are talking about. 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. 👍 |
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. |
@Josh-Cena Got it, thanks for the clarifying. That's true about formatting automatically in the collaborative large documents. Thanks! |
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