diff --git a/README.md b/README.md index 6b2691d6..aceaef54 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ 1. [Blocks](#blocks) 1. [Comments](#comments) 1. [Whitespace](#whitespace) - 1. [Leading Commas](#leading-commas) + 1. [Commas](#commas) 1. [Semicolons](#semicolons) 1. [Type Casting & Coercion](#type-coercion) 1. [Naming Conventions](#naming-conventions) @@ -802,9 +802,9 @@ **[[⬆]](#TOC)** -## Leading Commas +## Commas - - **Nope.** + - Leading commas: **Nope.** ```javascript // bad @@ -834,6 +834,34 @@ }; ``` + - 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)): + + > 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. + + ```javascript + // bad + var hero = { + firstName: 'Kevin', + lastName: 'Flynn', + }; + + var heroes = [ + 'Batman', + 'Superman', + ]; + + // good + var hero = { + firstName: 'Kevin', + lastName: 'Flynn' + }; + + var heroes = [ + 'Batman', + 'Superman' + ]; + ``` + **[[⬆]](#TOC)**