missing ) after argument list javascript – How to Solve SyntaxError: missing ) after argument list in JavaSCript?

missing ) after argument list javascript: In JavaScript, the “missing) after argument list” error occurs when we make a syntactic error when calling a function, such as forgetting to split its arguments by a comma. To resolve the error, ensure that any syntax errors in the arguments list of the function invocation are corrected.

Below are the examples where this “SyntaxError: missing ) after argument list” occurs.

Case#1: Forgetting to use comma(,) or ‘+’ to separate the values

// Solving SyntaxError: missing ) after argument list Error

// Here we forgot to use comma(,) or + to separate the values 
// while printing it on the console which leads to 
// SyntaxError: missing ) after argument list error
console.log('x' 'y'); 

Output:

console.log('x' 'y'); 
^^^

SyntaxError: missing ) after argument list
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)

Explanation:

Here we forgot to use comma(,) or + to separate the values while printing it
on the console which leads to // SyntaxError: missing ) after argument list error

Case#2: Printing ${} without the template strings

// Here we are printing ${} without the template strings 
// on the console.
// Hence SyntaxError: missing ) after argument list
console.log('The Metadata is:' + ${string_data});

Output:

console.log('The Metadata is:' + ${string_data}); 
^

SyntaxError: missing ) after argument list
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)

Explanation:

Here we are printing ${} without the template strings on the console leading to an error

Case#3: When there is no comma(,) between the arguments

// Here there is no comma(,) between arguments for separating them
// so, SyntaxError: missing ) after argument list occurs
mul(3 2);

Output:

mul(3 2); 
^

SyntaxError: missing ) after argument list
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)

Explanation:

Here there is no comma(,) between arguments for separating them.
so, SyntaxError: missing ) after argument list occurs

Case#4:

// Initialize the variables 
const EmpName = 'Nick';
const EmpId = 2354;
// Here there is no comma(,) between arguments
// so, SyntaxError: missing ) after argument list occurs
console.log(EmpName EmpId);

Output:

console.log(EmpName EmpId); 
^^^^^^^

SyntaxError: missing ) after argument list
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)

Case#5: When we forgot to close the bracket ) while calling a function

// Here we forgot to close the bracket ) while calling a function
// Hence SyntaxError: missing ) after argument list occurs
console.log("x", "y"

Output:

console.log("x", "y" 
^^^

SyntaxError: missing ) after argument list
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)

Solving SyntaxError: missing ) after argument list in JavaSCript

In case#1, the”missing ) after argument list” error is produced when a comma or the addition operator (+) is not added between the parameters in a function.

To resolve the error, ensure that any syntax errors in the parameter list of your function calls are corrected.

// Here we are using '+' operator for separation
console.log('welcome to ' + ' Btechgeeks');

// Here we are using comma(,) to separate the arguments
console.log('Btechgeeks'.slice(0, 3)); 

Output:

welcome to Btechgeeks
Bte

Delimiting a string with backticks (“)

Missing after argument list javascript: If you have a string that contains both double and single quotes, use a template literal, which is a string delimited by backticks (“).

// This is WRONG approch
const gvn_string1 = 'They\'re playing';

// Write the string as here while using both double and single quotes
const gvn_string2 = "They're playing"

// Or we can also write in this way using backticks(``)
const gvn_string3 = `They're playing`

Because template literals enclose the string with backticks, we can use both single and double quotes in the string’s contents without getting errors or having to escape any single or double quotes.

Conclusion

  • To resolve the “missing) after argument list” problem, ensure that any syntax errors are corrected when calling functions.
  • When the function is invoked, the error is frequently issued if the function arguments are not separated by a comma or the addition operator.