> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/web/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/web/js/grammar/token/literal/trailing-comma.md).

# trailing comma

* [JS](/web/js.md) ⟩ [grammar](/web/js/grammar.md) ⟩ [token](/web/js/grammar/token.md) ⟩ [literal](/web/js/grammar/token/literal.md) ⟩ trailing comma

{% hint style="success" %} <mark style="color:red;">**single**</mark> <mark style="color:purple;">**trailing comma**</mark>  is <mark style="color:green;">**allowed**</mark> in [array literal](/web/js/val/builtin/arr/create/arr.md) <mark style="color:yellow;">**/**</mark> [object literal](/web/js/val/obj/create/obj.md).

```javascript
let arr = [ 1, 2, 3, ];         // 💡 single trailing comma allowed, 
//                 ^            //     won't create "undefined element".

let obj = { name: 'Joy', age: 17, }
//                               ^ <---- trailing comma
```

:floppy\_disk: replit：[undefined elements in array literal](https://replit.com/@pegasusroe/undefined-elements-in-array-literal#index.js)
{% endhint %}

{% tabs %}
{% tab title="📘 手冊" %}

* [ ] [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)
* [ ] [Expressions and operators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators) ⟩&#x20;
* [ ] [Lexical Grammar](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar) ⟩ [Array Literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#array_literals)
  {% endtab %}

{% tab title="📗 參考" %}

* [ ] [JavaScript: The Definitive Guide](/web/master/ref/javascript-the-definitive-guide.md) ⟩&#x20;
  * [ ] 4.2：Object / Array Initializers
    {% endtab %}
    {% endtabs %}
