JavaScript SyntaxError – Missing ) after condition

This JavaScript exception missing ) after condition occurs if there is something wrong with if condition. Parenthesis should be after the if keyword.

Message:

SyntaxError: Expected ')' (Edge)
SyntaxError: missing ) after condition (Firefox)

Error Type:

SyntaxError

Cause of Error: Somewhere in the code there is something wrong with if condition how it is written. The condition should have written within the parenthesis.

Example 1: In this example, there is a missing “)” after if keyword so the error has occurred.



HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
<head>
    <title>Syntax Error</title>
</head>
<body>
    <script>
        if (3 < Math.PI {
            document.write("This will not print");   
        }
    </script>
</body>
</html>

chevron_right


Output(In console of Edge Browser):

Expected ')'

Example 2: In this example, there is a misuse of “is” keyword so the error has occurred. It should be “===”.

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
<head>
    <title>Syntax Error</title>
</head>
<body>
    <script>
        if (someVar is true) {
            document.write("This will not print");   
        }
    </script>
</body>
</html>

chevron_right


Output(In console of Edge Browser):

Expected ')' 

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.