Monday, November 18, 2024
Google search engine
HomeLanguagesJavascriptJavaScript SyntaxError – Missing ; before statement

JavaScript SyntaxError – Missing ; before statement

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 ';'
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments