JavaScript SyntaxError – Missing ; before statement
This JavaScript exception missing ; before statement occurs if there is a semicolon (;) missing in script.
Message:
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 ';'






Please Login to comment...