Syntax errors are one of the most common types of errors in JavaScript. They occur when the code is not written according to the rules of the language syntax.
In other words, syntax errors happen when the JavaScript interpreter encounters code that does not conform to its grammar rules. These errors prevent the code from running and need to be fixed before the program can be executed.
An example of a syntax error is forgetting to close a quotation mark in a string or misspelling a keyword. Let's take a look at an example:
JAVASCRIPT
1// Syntax error: missing closing parenthesis
2document.write("Hello, World!;");
xxxxxxxxxx
// Syntax error: missing closing parenthesis
document.write("Hello, World!;");
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment