JavaScript

SyntaxError: missing ) after argument list

While developing software, the probability of syntax errors is high. If you used incorrect pre-defined syntax then you might face an exception. Syntax errors are distinguished while compiling or parsing source code. This type of syntax error arises when an error such as typing error or missing operator is detected in a function. This can happen either due to a missing operator, typo error, or an unescaped string. Generally, JavaScript functions are dependent on brackets. So, in simple words, we can say that JavaScript is dependent on brackets to recognize the start and end of function calls.

This article explains the meaning of syntax error and it is important to understand why this error is triggered. In order to understand the issue and fix the problem, a walk-through has to be performed. “The missing after argument list” message shows that there is a possibility of syntax error within the method. This is probably due to the comma used erroneously where the list of arguments is not followed by other arguments.

For example, if you forgot to enclose the JavaScript function, then it triggers a syntax error. These types of error messages are shown in the browser.

(Edge Error)

SyntaxError: Expected ‘)

(Firefox Error)

SyntaxError: missing ) after argument list

Now we are going to provide a few examples. In the example below, we used Math.random() function to generate rapidly random numbers. But this function doesn’t work as the “+” operator is missing. Therefore, an error is triggered.

console.log('Generating Random Number: ' Math.random());

Output

The above error was triggered due to the missing “+” operator in the console.log function. So, you can easily fix this bug by inserting the “+” operator in the console.log function as shown in the example below.

console.log('Generating Random Number: ' + Math.random());

Output

The concatenation of two strings is illustrated in the example shown below. But the document.write() function doesn’t work as the “+” operator is missing. Therefore, an error is triggered.

<!DOCTYPE html>

<html>

<body>

<script>

var string1 = 'You are learning ';

var string2 = 'Syntax Error: missing ) after argument list';

document.write(string1 string2);

</script>

</body>

</html>

Output

Above mentioned error was triggered due to the missing “+” operator in the document.write() function. So, you can easily fix this bug by inserting the “+” operator in document.write() function as illustrated in the below-mentioned example.

<!DOCTYPE html>

<html>

<body>

<script>

var string1 = 'You are learning ';

var string2 = 'Syntax Error: missing ) after argument list';

document.write(string1 + string2);

</script>

</body>

</html>

Output

In the example below, we simply concatenate two strings by using the “+” operator but an “invalid or unexpected token” error is triggered. This error is triggered due to a typo error.

console.log('"Learning" + "missing ) error"");

If you want to fix this bug then you have to insert “ “ as shown in the example below.

console.log('"Learning" + "missing ) error"');

Conclusion

It is significant to note that as with other syntax errors, the error of missing parenthesis ‘)’ after the argument list can’t be caught by the ordinary try-catch block. This problem related to syntax is resolved through JavaScript. This generally implies that it doesn’t appear at the execution point where it can proceed toward the catch part of the block, since it doesn’t have the foggy idea of how to parse that effectively. This suggests that Syntax Errors are the major challenge. In this article, we have learned the concept of syntax error and also learned the reasons why this error is triggered. Then we went through the examples which clearly define how to fix this syntax error of missing parenthesis ‘)’ after the argument list.

About the author

Shehroz Azam

A Javascript Developer & Linux enthusiast with 4 years of industrial experience and proven know-how to combine creative and usability viewpoints resulting in world-class web applications. I have experience working with Vue, React & Node.js & currently working on article writing and video creation.