| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Trailing_commas | [Back] [Original] |
Get to know MDN better
JavaScript diff
JavaScript ECMAScript 5ECMAScript 2017
JavaScript
const arr = [
1,
2,
3,
];
arr; // [1, 2, 3]
arr.length; // 3
elision holesparse dense array / Array.prototype.forEach() Array.prototype.map()
const arr = [1, 2, 3, , ,];
arr.length; // 5
ECMAScript 5
const object = {
foo: "bar",
baz: "qwerty",
age: 42,
};
ECMAScript 2017
arguments length
function f(p) {}
function f(p,) {}
(p) => {};
(p,) => {};
class C {
one(a,) {}
two(a, b,) {}
}
const obj = {
one(a,) {},
two(a, b,) {},
};
f(p);
f(p,);
Math.max(10, 20);
Math.max(10, 20,);
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 ','
//
[a, b,] = [1, 2];
//
const o = {
p: 42,
q: true,
};
const { p, q, } = o;
const [a, ...b,] = [1, 2, 3];
// SyntaxError: rest element may not have a trailing comma
ECMAScript 5 JSON ES5 JSON
SyntaxError
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.parse("[1, 2, 3, 4 ]");
JSON.parse('{"foo" : 1 }');
| Web Proxy Viewer | New URL | Original Page |