Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

trailing comma javascript

Trailing comma is allowed in an array, object and function parameters. 
Now, this isn’t huge but it’s nice if in case we forget to close off or 
rather end a comma if we’re listing a bunch of items it doesn’t matter 
if we include that final extra one.

var list = [
    "one",
    "two",
    "three",   // It is valid
];

var obj = {
    one: "1",
    two: "2",
    three: "3", //  It is valid
}

function add(
    one,
    two,
    three, // It is valid
) {}
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #trailing #comma #javascript
ADD COMMENT
Topic
Name
2+9 =