Syntax can be thought of as the “grammar” of a programming language. Syntax establishes a set of rules for the characters and symbols used in the programming language.
A syntax error, then, is like a mistake in the “spelling.” Syntactical mistakes break the flow of a program; in fact, programs generally cannot run if they contain syntax errors.
Here’s an example:
function start()
move();
putBall();
}
There is a missing open bracket {
in the first line. When the computer attempts to run the program, it reaches the end of that line and expects to see a bracket next. However, the next thing it reads is a move();
command, thus causing an error.
This is like forgetting a period at the end of a sentence: Your reader expects a period to know when one sentence ends, but instead of a period all they see is a word from the next sentence. Humans can figure out little typos like this on the fly, but computers only do what the program explicitly states.