Quick reminder: trailing commas in object literals are legal in ECMAScript 5, trailing commas in arrays are ignored.
var obj = { first: 'Jane', last: 'Doe', age: 40, // trailing comma };The advantage of adding a trailing comma is that you can rearrange the innards of the literal without having to worry about commas being in the right places.
> var arr = [ 'a', 'b', 'c', ]; > arr [ 'a', 'b', 'c' ] > arr.length 3This goes so far that you need to write two trailing commas if you want to add a trailing hole [1]:
> var arr = [ 'a', 'b', , ]; > arr.length 3
> JSON.parse('{"x":1,}') SyntaxError: Unexpected token } > JSON.parse('[1,]') SyntaxError: Unexpected token ]