# 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 %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lochiwei.gitbook.io/web/js/grammar/token/literal/trailing-comma.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
