DEV Community

Discussion on: What programming best practice do you disagree with?

Collapse
 
michaeldober profile image
Michael Ober

For functions and methods, including anonymous lambda functions, I keep the opening brace on the next line by itself. For objects and everything I put the opening brace on the line with the declaration.

Will 'favoriteThings' even compile with that final comma?

Collapse
 
jckuhl profile image
Jonathan Kuhl

In JavaScript, the final comma is optional. In many other languages, that might not be the case.

Collapse
 
metruzanca profile image
Samuele Zanca • Edited

Oof, 6 months old buuuuttt. Yes, it does compile. Just like js, it's there for convenience when editing. You can't however do that in object initializers e.g.:

var obj = new MyClass
{
  item1, //shorthand if same name
  item2 = item2, //<—this comma gives error
};

(on mobile, fingers crossed for formatting)