Validating JavaScript
A different and complementary approach to checking your JavaScript code for problems is to use a validation program. This will check that it conforms to the correct syntax rules of the language. These programs are sometimes bundled with commercial JavaScript editors, or you can simply use Douglas Crockford's JavaScript Lint, which is available free online.
Here you can simply paste your code into the displayed window and click the button.
Don't be too dismayed if the program reports a lot of errors—just work through them one at a time. JSLint is very thorough and will even report various issues of coding style that wouldn't affect your code's running at all, but do help to improve how you program!