HouseTrip/javascript — pull request #3 by Karlotcha (2013-11-15 12:17:32+00:00)
Title: leading commas are good for you

Why leading commas are good? You may like it, or not... you may be used to it, or not (at all), but it should not be just a question of taste or habits.

First of all, it is not so weird, you can find this style in well-known javascript softwares - like Twitter Bootstrap or NPM (Node Package Manager). I don't want to use an [argument from authority](https://yourlogicalfallacyis.com/appeal-to-authority) - but I just want to notify you it is not a weird invention of mine.

So, why is it good?

Leading commas **improve indentation** and are more readable. Trailing commas **increase noise**.

Example:

```
commas = {
asdoifopiasdjf: 'asdiufhiu',
lasldjf: 'alsidasdfsdfdsfasdfijsdf',
alsdfjolisadjf: 'asldioff'
alkjsdfnosnad: 'aslfodsdfoi',
alkjsdfnosnad: 'aslfodsfisadfoi',
};
```

vs

```
var commas = {
asdoifopiasdjf: 'asdiufhiu',
, lasldjf: 'alsidasdfsdfdsfasdfijsdf',
, alsdfjolisadjf: 'asldioff'
alkjsdfnosnad: 'aslfodsdfoi'
, alkjsdfnosnad: 'aslfodsfisadfoi'
,
};
```

Leading commas also help to spot **missing commas** (previous example) or additional trailing commas (previous example again).
Missing commas are dangerous! It can leak variables, break IE, kill kitties.

I didn't start javascript with this style and when I started to use it, I was feeling weird. But now I just love it, and I think it is objectively a better style.