Open In App

JavaScript SyntaxError – Missing ; before statement

Last Updated : 22 May, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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

Message:

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

Error Type:

SyntaxError

Cause of Error: Somewhere in the 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.

Javascript




// invalid string
let GFG = 'This is GFG's platform'; 
console.log(GFG);


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, 

Javascript




let GFG = {};
let GFG.prop_1 = 'Val_1';
console.log(JSON.stringify(GFG));


Output(In console of Edge Browser): 

SyntaxError: Expected ';'

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads