JavaScript SyntaxError: missing ) After Argument List
Last updated on: by Digamber
Let us understand SyntaxError: missing ) after argument list error in JavaScript. This error occurs when a function is called in JS. It can occur due to various reasons.
Error Reasons:
- missing operator
- typo error
- unescaped string
Check out some examples
As you can see we are trying to generate a random number using Math.random()
method In the below example. However, this method won’t work because we are missing “+” operator in the console.log() method.
console.log('Random Number: ' Math.random());
// Output: SyntaxError: missing ) after argument list
Let us fix this SyntaxError: missing ) after argument list error in JavaScript by putting "+"
operator and check out the output below.
console.log('Random Number: ' + Math.random());
// Output: some random number between 0 and 1
SyntaxError: Invalid or unexpected token
console.log('"Hello" + "World"");
// Output: SyntaxError: Invalid or unexpected token
As we can see JavaScript throw SyntaxError: Invalid or unexpected token error because of missing " ' "
.
console.log('"Hello" + "World""');
// Output: "Hello" + "World""