How to Solve the "SyntaxError: missing ) after argument list" in JavaScript
The SyntaxError: missing ) after argument list is a common syntax error in JavaScript. It occurs when the JavaScript engine is trying to parse the arguments of a function call but encounters a syntax that it doesn't understand. While the message mentions a missing parenthesis ), the root cause is almost always a different syntax mistake within the argument list.
This guide will explain the common mistakes that trigger this error and show you how to fix them.
The Core Problem: Invalid Syntax in a Function's Argument List
This error is thrown by the JavaScript parser when it is reading the code inside a function call's parentheses (). It expects a comma-separated list of expressions (arguments). When it finds two arguments next to each other without a comma or a valid operator between them, it gets confused and reports a syntax error.
Cause 1 (Most Common): Missing Comma Between Arguments
This is the most frequent cause of the error. You intend to pass multiple arguments to a function but forget to separate them with a comma.
Example of problem:
// Problem: Two arguments are next to each other without a separator.
function sum(a, b) {
return a + b;
}
sum(10 15); // ⛔️ SyntaxError: missing ) after argument list
The parser sees 10 and then 15 and doesn't know what to do, as it was expecting a comma or a closing parenthesis.
Solution: Always separate arguments in a function call with a comma.
// ✅ Correct: Arguments are separated by a comma.
function sum(a, b) {
return a + b;
}
sum(10, 15); // Returns 25
Cause 2: Incorrect String Concatenation
This often happens when you try to join two string literals or a string and a variable without using the + operator.
Example of problem:
// Problem: Two string literals without the `+` operator.
console.log('Hello' 'World'); // ⛔️ SyntaxError
const name = 'Alice';
console.log('Welcome, ' name); // ⛔️ SyntaxError
Solution: use the addition (+) operator to concatenate strings or use a template literal.
// ✅ Correct: Using the `+` operator
console.log('Hello' + 'World');
const name = 'Alice';
console.log('Welcome, ' + name);
// ✅ Correct (Modern): Using a template literal
console.log(`Welcome, ${name}`);
Cause 3: Using Template Literal Syntax in a Regular String
Template literals (${...}) are a special feature that only works inside strings delimited by backticks (`). Using this syntax in a regular single or double-quoted string will cause a syntax error.
Example of problem:
// Problem: Using `${...}` inside a single-quoted string.
const data = 'some data';
console.log('Metadata: ${data}'); // ⛔️ SyntaxError
Solution: ensure you are using backticks for template literals.
// ✅ Correct: Using backticks for the template literal.
const data = 'some data';
console.log(`Metadata: ${data}`); // Output: "Metadata: some data"
Cause 4: A Missing Closing Parenthesis
While less common, the error message can be literal. If you have a complex, nested function call, you might simply forget a closing parenthesis.
Example of problem:
// Problem: The outer console.log is missing its closing parenthesis.
console.log("The result is:", sum(10, 5) // ⛔️ SyntaxError
Solution: carefully check your parentheses to ensure that every opening ( has a corresponding closing ). Your code editor's bracket highlighting can be very helpful for this.
// ✅ Correct: All parentheses are balanced.
console.log("The result is:", sum(10, 5));
Conclusion
The SyntaxError: missing ) after argument list is almost always a signal that you have made a simple syntax mistake inside a function call.
To fix it, check for these common issues:
- Missing commas between multiple arguments.
- Missing
+operators between strings you are trying to concatenate. - Incorrect use of
${...}in a string that is not a template literal (i.e., not using backticks`). - A genuinely missing closing parenthesis
)in a complex expression.