What is syntax error?

Computer language has really strict rules and syntax errors mean you have broken one of those rules.

Computer language has really strict rules and syntax errors mean you have broken one of those rules. The syntax exists in both common languages. That's how words are arranged to make meaningful sentences.

While people can adapt and structure a sentence in many ways while ensuring that the sentence is meaningful, the computer needs extremely accurate instructions. If we break the rules even a little, a command can still make sense to people, but the computer will not be able to explain it.

What is syntax error? Picture 1What is syntax error? Picture 1

Syntax in human language

Imagine someone telling you an English sentence with the following content: 'I saw a woman over there with a telescope'. There are many ways you can interpret this sentence:

  1. "Using a telescope, I observed a woman who was over there." (Using a telescope, I observed a woman over there).
  2. "I observed a woman, who was over there, and she had a telescope." (I observed a woman over there and she had a telescope).
  3. "I đã có một người dùng và một telescope, chúng cần cả sau có." (I observed a woman and a telescope, both over there).
  4. "I was over there and I observed a woman who had a telescope." (I'm over there and observed a woman with a telescope).
  5. "Sometimes, I go over a woman using a telescope." (Sometimes, I go there and see a woman using a telescope).

Because you are human, you can apply the context to this sentence. Based on the location of the word 'over there' and possibly any previous information related to the telescope, you will assume the first or second explanation is correct.

What is syntax error in computer language?

How the syntax errors are handled in different languages ​​can vary a lot. A few examples are given here:

  1. Excel: If you enter the formula with an incorrect syntax on a cell in Excel, you will see #VALUE displayed in the cell. It does not explicitly indicate that it is a syntax error, but it is true.
  2. HTML: You can break a lot of rules in HTML and a website will still display well on most browsers. The problem with this is that behavior can become unpredictable. A page may look fine on your browser, but does not work on someone else's browser. You should check your code with W3C authentication service, which provides detailed information about errors in HTML code.
  3. JavaScript: If there is a syntax error in JavaScript, it will prevent thread (thread) from running. However, the rest of the code, contained in other threads, will still be executed, provided they are not dependent on the flow of the error. When running code in the browser, usually nothing happens. You will not receive an error message and the code will not run.

What to do if you get a syntax error?

What is syntax error? Picture 2What is syntax error? Picture 2

If your code fails due to a syntax error, there are some things you can do to debug your code.

1. You need to find out exactly where the syntax error is. In many languages, you will receive a detailed error message, telling you where the error is in the code. If you know which instructions have errors, you can check the documentation for examples of correct syntax.

2. If you are not sure where the problem is, you can try dividing the code into smaller sections, see if each section works properly and determine which part contains the error. Repeating this process can determine where the problem is and fix it.

3. If you need to debug a lot of web code, it may be worth considering using developer tools.

4 ★ | 1 Vote