SyntaxError: missing ) after argument list in JavaScript

avatar
Borislav Hadzhiev

Last updated: Mar 2, 2024
3 min

banner

# 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. forgetting 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 console.log('Metadata: ' + ${data}); // ๐Ÿ‘ˆ๏ธ using ${} without template strings // ----------------------------------------------------- function sum(a, b) { return a + b; } // โ›”๏ธ Uncaught SyntaxError sum(10 15); // ๐Ÿ‘ˆ๏ธ forgot comma between arguments // ----------------------------------------------------- const country = 'Chile'; const age = 30; // โ›”๏ธ Uncaught SyntaxError console.log(country age); // ๐Ÿ‘ˆ๏ธ forgot comma or plus between arguments // ----------------------------------------------------- // โ›”๏ธ Uncaught SyntaxError console.log("a", "B" // ๐Ÿ‘ˆ๏ธ forgot the closing ) when calling function

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

index.js
// โ›”๏ธ Uncaught SyntaxError: missing ) after argument list console.log('a' 'b'); // ๐Ÿ‘ˆ๏ธ forgot comma or +

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
The code for this article is available on GitHub

If you need to concatenate strings, use the addition (+) operator.

index.js
console.log('hello ' + 'world'); // ๐Ÿ‘‰๏ธ hello world console.log('age: ' + String(30)); // ๐Ÿ‘‰๏ธ age: 30

If you need to pass multiple arguments to the function, separate them by commas.

index.js
console.log('hello'.slice(0, 2)); // ๐Ÿ‘‰๏ธ 'he'

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.

Here is another example of how the error occurs.

index.js
function sum(a, b) { return a + b; } // โ›”๏ธ Uncaught SyntaxError: missing ) after argument list sum(10 15); // ๐Ÿ‘ˆ๏ธ forgot comma between arguments

To solve the error, add a comma between the arguments of the function.

index.js
function sum(a, b) { return a + b; } const result = sum(10, 15); console.log(result); // ๐Ÿ‘‰๏ธ 25
The code for this article is available on GitHub

# Make sure to terminate your string literals

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'; // โœ… alternate quotes const str2 = "it's him" // โœ… template literal const str3 = `it's him` // โœ… a template literal with a variable const num = 42; const str4 = `The number is ${num}`; console.log(str4); // ๐Ÿ‘‰๏ธ The number is 42

make sure to terminate your string literals

The code for this article is available on GitHub

Template literals wrap the string using backticks, so can 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.

# Make sure you don't have any missing parentheses or brackets

Here is another example of how the error occurs.

index.js
// โ›”๏ธ SyntaxError: missing ) after argument list console.log("a", "B" // ๐Ÿ‘ˆ๏ธ forgot the closing ) when calling function

Add the closing parenthesis to resolve the error.

index.js
console.log("a", "B")

make sure you dont have missing parentheses or brackets

A common cause of the error is having a missing or extra parenthesis, square bracket, curly brace, comma, colon or quote.

You can look at the error message in your browser's Console tab or your Node.js terminal to see on which line the error occurred.

The code for this article is available on GitHub
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.

Copyright ยฉ 2024 Borislav Hadzhiev