Get to know MDN better
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
* Some parts of this feature may have varying levels of support.
Trailing commas (sometimes called "final commas") can be useful when adding new elements, parameters, or properties to JavaScript code. If you want to add a new property, you can add a new line without modifying the previously last line if that line already uses a trailing comma. This makes version-control diffs cleaner and editing code might be less troublesome.
JavaScript has allowed trailing commas in array literals since the beginning. Trailing commas are now also allowed in object literals, function parameters, named imports, named exports, and more.
JSON, however, disallows all trailing commas.
JavaScript allows trailing commas wherever a comma-separated list of values is accepted and more values may be expected after the last item. This includes:
In all these cases, the trailing comma is entirely optional and doesn't change the program's semantics in any way.
It is particularly useful when adding, removing, or reordering items in a list that spans multiple lines, because it reduces the number of lines that need to be changed, which helps with both editing and reviewing the diff.
JavaScript ignores trailing commas in array literals:
If more than one trailing comma is used, an elision (or hole) is produced. An array with holes is called sparse (a dense array has no holes). When iterating arrays for example with Array.prototype.forEach() or Array.prototype.map(), array holes are skipped. Sparse arrays are generally unfavorable, so you should avoid having multiple trailing commas.
Trailing commas in object literals are legal as well:
Trailing commas are also allowed in function parameter lists.
The following function definition pairs are legal and equivalent to each other. Trailing commas don't affect the length property of function declarations or their arguments object.
The trailing comma also works with method definitions for classes or objects:
The following function invocation pairs are legal and equivalent to each other.
Function parameter definitions or function invocations only containing a comma will throw a SyntaxError. Furthermore, when using rest parameters, trailing commas are not allowed:
A trailing comma is also allowed within a destructuring pattern:
However, a trailing comma is not allowed after the rest element, if present
As JSON is based on a very restricted subset of JavaScript syntax, trailing commas are not allowed in JSON.
Both lines will throw a SyntaxError:
Omit the trailing commas to parse the JSON correctly:
Trailing commas are valid in named imports and named exports.
Trailing commas are only allowed in dynamic imports if the runtime also implements the second options parameter.
Note: The trailing comma in a quantifier actually changes its semantics from matching "exactly n" to matching "at least n".
Enable JavaScript to view this browser compatibility table.
This page was last modified on Jul 8, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.