Quick reminder: trailing commas in object literals are legal in ECMAScript 5, trailing commas in arrays are ignored.

Trailing commas in object literals

var obj = { first: 'Jane', last: 'Doe', age: 40, // trailing comma };

Trailing commas in array literals

> var arr = [ 'a', 'b', 'c', ]; > arr [ 'a', 'b', 'c' ] > arr.length 3

> var arr = [ 'a', 'b', , ]; > arr.length 3

Trailing commas in JSON

> JSON.parse('{"x":1,}') SyntaxError: Unexpected token } > JSON.parse('[1,]') SyntaxError: Unexpected token ]

What browsers support object literals with trailing commas?

References

Thus, if you can afford to ignore older JavaScript engines, you can write your object literals like this: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.Similarly, trailing commas in arrays are ignored:This goes so far that you need to write two trailing commas if you want to add a trailing hole [1] JSON [2] is based on JavaScript’s syntax prior to ECMAScript 5, which means that trailing commas are illegal:Most browsers support object literals with trailing commas. You are only out of luck in Internet Explorer 8 and earlier ( compatibility table ).