How to find Javascript syntax errors? [closed]

Ctrl + Shift + J in firefox, if you don't catch your mistakes until runtime. Of course firebug works better, but this is a quick way.


http://www.javascriptlint.com/

Here are some common mistakes that JavaScript Lint looks for:

  • Missing semicolons at the end of a line.
  • Curly braces without an if, for, while, etc.
  • Code that is never run because of a return, throw, continue, or break.
  • Case statements in a switch that do not have a break statement.
  • Leading and trailing decimal points on a number.
  • A leading zero that turns a number into octal (base 8).
  • Comments within comments.
  • Ambiguity whether two adjacent lines are part of the same statement.
  • Statements that don't do anything.

Douglas Crockford's Jslint: http://www.jslint.com/

But be warned, it will hurt your feelings ;-)


Chrome : Ctrl + Shift + J : this will bring up the JavaScript console. You can click the scripts tab to review page scripts.

FireFox : Install firebug and run it to get a similar console to the above stated chrome utilities.

IDE : You may wish to use netbeans or Eclipse which both offer syntax highlighting and code completion for JavaScript. These will indicate syntax errors at code time.

jslint/jshint : These tools offer code suggestions to improve your code quality and reduce the possibility of errors (logic) but will also break on syntax and other errors.


Try JSlint

It's a great utility for debugging Javascript. If you're using the jQuery library, there is a plugin being developed and was just recently released, similarly called jQuery Lint