Historically speaking, ES3 did NOT allow a trailing comma when defining an object literal. This was one thing that IE did get right, but most other bowser vendors went against the spec and allowed it anyways. So technically it was a bug in the other browsers that supported it. In ES3, an ObjectLiteral
was defined as,
ObjectLiteral
{ }
{ PropertyNameAndValueList }
Later ES5 resolved this issue by going with the majority and legitimizing the trailing comma by putting it in the spec. Now an ObjectLiteral
is defined as,
ObjectLiteral
{ }
{ PropertyNameAndValueList }
{ PropertyNameAndValueList , }
Notice the trailing comma at the end.
Although the trailing comma is defined in an object literal, it is still not allowed in JSON according to ES5. So while the following object literal is valid,
{ foo: "bar", }
the following JSON is not,
'{ "foo": "bar", }'
The grammar for a JSONObject is,
JSONObject
{ }
{ JSONMemberList }
JSONMemberList
JSONMember
JSONMemberList , JSONMember
JSONMember
JSONString : JSONValue
In short, if you don't want to worry about spec or browser quirks, then do NOT add a trailing comma.