JavaScript Errors

 

JavaScript Errors

This is part eight of the JavaScript tutorial. If you missed the previous lessons, make sure you complete them prior to viewing this JavaScript Errors tutorial.

When writing your own JavaScript code, you may receive an error. As JavaScript coding is very sensitive and must be written perfectly, it is very easy to make a mistake, which will cause an error.

In JavaScript, there are two types of errors: Syntax Errors and Runtime Errors. Syntax errors usually mean that the code is written wrong in some way. For instance, you may have misspelled a word in the code or left a variable undefined.

 
JavaScript Runtime Errors, on the other hand, mean that the script is broken somewhere. It may be that a command isn’t all the way on the left hand side of the page, or it may be because you’ve accidentally added space between lines of code that shouldn’t be there. Again, JavaScript is picky.

Finding errors isn’t that difficult. Browsers will popup a box that tells you there is an error, and in most cases, will even tell you what line that error is on. Simply count down the lines from the top of your document, and include blank lines when counting to find your errors. You may even see multiple errors at one time on that error popup. If this is the case, start at the top and fix each error as you find it, and then run the script again after each fix. Often, one fix will correct numerous errors.

This concludes the JavaScript Errors lesson. In the next lesson, we will focus on JavaScript Food Chain.

 
This concludes the JavaScript Errors lesson. In the next lesson, we will focus on the JavaScript Food Chain.