Last updated 2 years ago
JS ⟩ grammar ⟩ token ⟩ literal ⟩ trailing comma
single trailing comma is allowed in array literal / object literal.
let arr = [ 1, 2, 3, ]; // 💡 single trailing comma allowed, // ^ // won't create "undefined element". let obj = { name: 'Joy', age: 17, } // ^ <---- trailing comma
replit:undefined elements in array literal
Array
Expressions and operators ⟩
Lexical Grammar ⟩ Array Literals
JavaScript: The Definitive Guide ⟩
4.2:Object / Array Initializers