close
The Wayback Machine - https://web.archive.org/web/20211120153239/https://www.geeksforgeeks.org/javascript-syntaxerror-missing-before-statement/
Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

JavaScript SyntaxError – Missing ; before statement

  • Last Updated : 24 Jul, 2020

This JavaScript exception missing ; before statement occurs if there is a semicolon (;) missing in script.

Message:

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

SyntaxError: Expected ';' (Edge)
SyntaxError: missing ; before statement (Firefox)

Error Type:

SyntaxError

Cause of Error: Somewhere in code, there is a missing semicolon (;). You need to provide it so that JavaScript can parse the source code without any error.



Example 1: In this example, the string is not escaped properly and JavaScript expecting a “;”, so the error has occurred.

HTML




<!DOCTYPE html>
<html>
<head>
    <title>Syntax Error</title>
</head>
<body>
    <script>
        // invalid string
        var GFG = 'This is GFG's platform';  
        document.write(GFG);
    </script>
</body>
</html>

Output(In console of Edge Browser):

SyntaxError: Expected ';'

Example 2: In this example, the properties of an object is declared with the var declaration, Which is invalid. So the error has occurred, 

HTML




<!DOCTYPE html>
<html>
<head>
    <title>Syntax Error</title>
</head>
<body>
    <script>
        var GFG = {};
        var GFG.prop_1 = 'Val_1';  
        document.write(JSON.stringify(GFG));
    </script>
</body>
</html>

Output(In console of Edge Browser): 

SyntaxError: Expected ';'



My Personal Notes arrow_drop_up
Recommended Articles
Page :