SyntaxError: missing ) after argument list in JavaScript

avatar

Borislav Hadzhiev

Last updated: Jul 25, 2022

banner

Photo from Unsplash

SyntaxError: missing ) after argument list in JavaScript #

The "SyntaxError: missing ) after argument list" occurs when we make a syntax error when calling a function, e.g. forget to separate its arguments with a comma. To solve the error make sure to correct any syntax errors in the arguments list of the function invocation.

javascript syntax error missing after argument list

Here are some examples of how the error occurs:

index.js
// ⛔️ Uncaught SyntaxError: missing ) after argument list console.log('a' 'b'); // 👈️ forgot comma or + // ⛔️ Uncaught SyntaxError: missing ) after argument list console.log('Metadata: ' + ${data}); // 👈️ using ${} without template strings function sum(a, b) { return a + b; } // ⛔️ Uncaught SyntaxError: missing ) after argument list sum(10 15); // 👈️ forgot comma between arguments const country = 'Chile'; const age = 30; // ⛔️ Uncaught SyntaxError: missing ) after argument list console.log(country age); // 👈️ forgot comma or plus between arguments // ⛔️ Uncaught SyntaxError: missing ) after argument list console.log("a", "B" // 👈️ forgot the closing ) when calling function

The first example shows how the "missing ) after argument list" error is thrown when we forget to add a comma or the addition operator (+) between the arguments in a function.

To solve the error, make sure to correct any syntax errors in the argument list of your function calls.

index.js
console.log('hello' + ' world'); // 👈️ use + operator console.log('hello'.slice(0, 2)); // 👈️ separate arguments by comma

If you can't determine where the error is thrown, look at the error message in your browser's console or your terminal (if using Node.js).

javascript syntax error missing after argument list

The screenshot above shows that the error was thrown in the index.js file on line 19.

If you have a string where you're mixing up double and single quotes, it's best to use a template literal, which is a string delimited with backticks (``).

index.js
// ⛔️ don't do this const str1 = 'it\'s him'; // ✅ do this const str2 = "it's him" // ✅ or this const str3 = `it's him`

Since template literals wrap the string using backticks, we are able to use both single and double quotes in the contents of the string, without getting any errors and without having to escape any single or double quotes.

Conclusion #

To solve the "missing ) after argument list" error, make sure to correct any syntax errors when calling functions. The error is often thrown when function arguments aren't separated by a comma when the function is invoked.

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.