Skip to content

Commit bf87eec

Browse files
committed
[commas] add section on additional trailing commas. fixes airbnb#75
1 parent e3e3cc1 commit bf87eec

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

README.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
1. [Blocks](#blocks)
1818
1. [Comments](#comments)
1919
1. [Whitespace](#whitespace)
20-
1. [Leading Commas](#leading-commas)
20+
1. [Commas](#commas)
2121
1. [Semicolons](#semicolons)
2222
1. [Type Casting & Coercion](#type-coercion)
2323
1. [Naming Conventions](#naming-conventions)
@@ -802,9 +802,9 @@
802802

803803
**[[⬆]](#TOC)**
804804

805-
## <a name='leading-commas'>Leading Commas</a>
805+
## <a name='commas'>Commas</a>
806806

807-
- **Nope.**
807+
- Leading commas: **Nope.**
808808

809809
```javascript
810810
// bad
@@ -834,6 +834,34 @@
834834
};
835835
```
836836

837+
- Additional trailing comma: **Nope.** This can cause problems with IE6/7 and IE9 if it's in quirksmode. Also, in some implementations of ES3 would add length to an array if it had an additional trailing comma. This was clarified in ES5 ([source](http://es5.github.io/#D)):
838+
839+
> Edition 5 clarifies the fact that a trailing comma at the end of an ArrayInitialiser does not add to the length of the array. This is not a semantic change from Edition 3 but some implementations may have previously misinterpreted this.
840+
841+
```javascript
842+
// bad
843+
var hero = {
844+
firstName: 'Kevin',
845+
lastName: 'Flynn',
846+
};
847+
848+
var heroes = [
849+
'Batman',
850+
'Superman',
851+
];
852+
853+
// good
854+
var hero = {
855+
firstName: 'Kevin',
856+
lastName: 'Flynn'
857+
};
858+
859+
var heroes = [
860+
'Batman',
861+
'Superman'
862+
];
863+
```
864+
837865
**[[⬆]](#TOC)**
838866
839867

0 commit comments

Comments
 (0)