FrontendDeveloper.in

ECMAScript question detail

Trailing commas

Trailing commas are allowed in parameter definitions and function calls

 function func(a,b,) { // declaration
console.log(a, b);
 }
func(1,2,); // invocation

But if the function parameter definition or function call only contains a comma, a syntax error will be thrown

 function func1(,) {  // SyntaxError: missing formal parameter
console.log('no args');
 };
func1(,); // SyntaxError: expected expression, got ','

Note: Trailing commas are not allowed in Rest Parameters and JSON.

ES2018 Or ES9

Back to all ECMAScript questions
Get LinkedIn Premium at Rs 399