What Is a Syntax Error on a Web Page?

What Is a Syntax Error on a Web Page? thumbnail
Syntax errors sometimes occur on Web Pages

A syntax error is a type of programming error, or "bug", that can occur when a programmer accidentally misuses an element of a programming language. Just as human languages have rules about punctuation, grammar and spelling, programming languages have rules about how the instructions to the computer must be expressed. If a programmer breaks those rules when creating the code to run on a Web page, the Web page may respond with a syntax error.

  1. Programming in Web Pages

    • Just like programs that run on your computer, Web pages often have some programming code behind them. That code can be found contained within the HTML page that the browser downloads, in a separate file linked to by that HTML page, or on the server that sent the HTML file to your browser. In all those cases, the code is being used to create something more than a plain text page (possibly with some images). The code means that the page is dynamic or interactive in some way.

      Any code must be carefully written to avoid mistakes. Mistakes in the programming language itself are called syntax errors.

    Causes

    • If a syntax error occurs, it's likely that the programmer has made a typo which means that the computer can't understand what the programmer has written. It's like a punctuation mistake in a written sentence.

      As an example, often programmers are required to put statements in brackets. If the number of opening brackets do not match with the number of closing brackets, a syntax error will occur. Because computer code can get lengthy and complicated, this kind of mistake can be quite easy to make.

      Nowadays, programmers can use tools to write computer code that will highlight most syntax errors and warn of misspellings of frequently used programming terms, or if the number of opening and closing brackets do not add up. Such tools are called IDEs or Integrated Development Environments.

    Effects

    • Depending on where the error occurs, the syntax error might stop the Web page from showing at all and just present an error page. This is most likely to happen if the error occurs on code being run by the server that delivers the Web page. Alternately, a syntax error might stop displaying the page at the point where the error occurred, or the page itself might display in full, only with some of its functionality broken.

      Different programming languages have different ways of showing that a syntax error has occurred. Most will report something like "A syntax error has occurred: Line 51". Some languages are more specific, and will give you a clue as to what the error is. If this is the case the error might be "A syntax error has occurred: Line 51 (Mismatched Brackets)"

    Fixing Syntax Errors

    • If you encounter a syntax error on a Web page while browsing, you can't really do much about it as the fault lies with the original programmer for that page.

      If you are doing some Web page programming and a syntax error arises, check the error message to see what clues it can give you as to the location of the error, and go over your code carefully. Don't forget to check the areas above and below the line that gives an error. If you have failed to close a bracket earlier, for example, the error might not occur until the program realizes things have not been accurately bracketed off, much further down the line. Even comments in code (which are not usually run by the browser or the server) can cause syntax errors if they are not correctly marked as such.

    Similar Errors

    • Not all programming errors from typos are immediately identified as syntax errors. If a programmer misspells a function name, a variable or a method you might get an response such as "Method X does not exist" Strictly speaking, however, these are still syntax errors. For simplicity's sake, it's always a good idea to follow a set of naming and spelling conventions for such things, so that any discrepancies are easier to find.

Related Searches:

References

Resources

  • Photo Credit stock image of binary code sphere image by Ruslana Stovner from Fotolia.com

Comments

You May Also Like

  • How to Fix Syntax Error

    Using the correct syntax is vital when programming applications or creating websites. A single missing comma or semicolon can cause your code...

  • How to Get Rid of Invalid Syntax Errors?

    There may be times when an "Invalid Syntax Errors" message appears in the middle of your Web browser while you are surfing...

  • What Is a Syntax Error?

    Syntax errors in computer programming happen during the process of writing code to run a program. If the programmer makes an error,...

  • How to Fix a JSP Syntax Error

    Open the Web page in other major Web browser applications. Verify that the line number containing the code is the same in...

  • How to Debug a Syntax Error

    Debugging syntax errors is one of the key tasks in programming. Having the ability to find and fix errors is what makes...

  • Types of Syntax Errors

    Types of Syntax Errors. Syntax errors are programming mistakes from a typo, incorrect variable data type or other mistyped coding error. They...

  • How to Get Rid of the Invalid Syntax Error Virus

    When you try to visit a website that has an error in the URL or when you try to perform an online...

  • What Is a Syntax Error in Java?

    Java syntax errors refer to mistakes made by a programmer in implementing the grammar of the Java programming language. It doesn't cover...

  • How to Fix an Invalid Syntax Error

    One of the most frustrating problems for web programmers is that of syntax errors. This is particularly true for JavaScript or Java...

Related Ads

Featured