I wonder why putting a comma at the end of a single element is legal in a JavaScript array:
var array = [
'foo', // no error in IDE
]
while putting it at the end of a single element in an object is illegal (at least my IDE – WebStorm – is flagging about an error):
var object = {
'foo': 'bar', // error in IDE
}
Is this really illegal in JavaScript?
In the ECMAScript 5 specification it is legal:
ObjectLiteral : { } { PropertyNameAndValueList } { PropertyNameAndValueList , }It was illegal in ECMAScript 3.
ObjectLiteral : { } { PropertyNameAndValueList }I believe it was made legal to make things like this doable.
Instead of this:
Saving some of the programmers time.