Home » » Dealing with JavaScript Errors

Dealing with JavaScript Errors

You may have gotten errors when you tried to run scripts in the previous examples. Generally, errors appear not because the script is bad, but because it isn't written correctly. JavaScript, unlike HTML, is not very forgiving. It has to be written exactly right.

In JavaScript, there are two 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.

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.
Share this article :

0 comments:

Post a Comment

 
Copyright © Online Business - All Rights Reserved
Proudly powered by Blogger