The ECMAScript 2017 feature “Trailing commas in function parameter lists and calls” was proposed by Jeff Morrison.
Trailing commas in parameter definitions are now legal:
Similarly, trailing commas in function calls are now also legal:
Trailing commas are ignored in object literals:
And they are also ignored in Array literals:
Why is that useful? There are two benefits.
First, rearranging items is simpler, because you don’t have to add and remove commas if the last item changes its position.
Second, it helps version control systems with tracking what actually changed. For example, going from:
leads to both the line with
'foo' and the line with
'bar' being marked as changed, even though the only real change is the latter line being added.
Given the benefits of optional and ignored trailing commas, the feature brings them to parameter definitions and function calls.
For example, the following function declaration causes a SyntaxError in ECMAScript 6, but is now legal:
Similarly, this invocation of
foo() is now syntactically legal: