[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Trailing_commas [Back]  [Original]

- JavaScript | MDN

MDN Web Docs

View in English Always switch to English

Baseline *

20157

*

() JavaScript

JavaScript

JSON

JavaScript

diff
  [
    "foo",
+   "baz",
    "bar",
-   "baz",
  ]

JavaScript

js
const arr = [
  1,
  2,
  3,
];

arr; // [1, 2, 3]
arr.length; // 3

2 () Array.prototype.forEach() Array.prototype.map()

js
const arr = [1, 2, 3, , ,];
arr.length; // 5

js
const object = {
  foo: "bar",
  baz: "qwerty",
  age: 42,
};

2 length arguments

js
function f(p) {}
function f(p,) {}

(p) => {};
(p,) => {};

js
class C {
  one(a,) {}
  two(a, b,) {}
}

const obj = {
  one(a,) {},
  two(a, b,) {},
};

2

js
f(p);
f(p,);

Math.max(10, 20);
Math.max(10, 20,);

SyntaxError

js
function f(,) {} // SyntaxError: missing formal parameter
(,) => {};       // SyntaxError: expected expression, got ','
f(,)             // SyntaxError: expected expression, got ','

function f(...p,) {} // SyntaxError: parameter after rest parameter
(...p,) => {}        // SyntaxError: expected closing parenthesis, got ','

js
// 
[a, b,] = [1, 2];

// 
const o = {
  p: 42,
  q: true,
};
const { p, q, } = o;

js
const [a, ...b,] = [1, 2, 3];
// SyntaxError: rest element may not have a trailing comma

JSON

JSON JavaScript JSON

SyntaxError

js
JSON.parse("[1, 2, 3, 4, ]");
JSON.parse('{"foo" : 1, }');
// SyntaxError JSON.parse: unexpected character
// at line 1 column 14 of the JSON data

JSON

js
JSON.parse("[1, 2, 3, 4 ]");
JSON.parse('{"foo" : 1 }');

js
import {
  A,
  B,
  C,
} from "D";

import { X, Y, Z, } from "W";

import { A as B, C as D, E as F, } from "Z";

js
export {
  A,
  B,
  C,
};

export { A, B, C, };

export { A as B, C as D, E as F, };

2 options

js
import("D",);
import(
  "D",
  { with: { type: "json" } },
);

: n n

js
/x{2}/; // Exactly 2 occurrences of "x"; equivalent to /xx/
/x{2,}/; // At least 2 occurrences of "x"; equivalent to /xx+/
/x{2,4}/; // 2 to 4 occurrences of "x"; equivalent to /xxx?x?/

ECMAScript 2027 LanguageSpecification
# prod-Elision
ECMAScript 2027 LanguageSpecification
# prod-ObjectLiteral
ECMAScript 2027 LanguageSpecification
# prod-ArrayLiteral
ECMAScript 2027 LanguageSpecification
# prod-Arguments
ECMAScript 2027 LanguageSpecification
# prod-FormalParameters
ECMAScript 2027 LanguageSpecification
# prod-CoverParenthesizedExpressionAndArrowParameterList
ECMAScript 2027 LanguageSpecification
# prod-NamedImports
ECMAScript 2027 LanguageSpecification
# prod-NamedExports
ECMAScript 2027 LanguageSpecification
# prod-QuantifierPrefix
ECMAScript 2027 LanguageSpecification
# prod-annexB-InvalidBracedQuantifier


Web Proxy Viewer  |  New URL  |  Original Page