How to find Javascript syntax errors

I am writing a JavaScript section of code and am making huge amounts of silly mistakes in the syntax. But the only way to find what line the error is on is to start commenting out the section of code I just wrote and reload it into the browser to narrow down where my missing ');' is.

How do you "compile" a JavaScript source to make sure it is syntactically correct so that I can debug it in the browser?


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 ;-)

    链接地址: http://www.djcxy.com/p/11946.html

    上一篇: 解析错误:语法错误,意外(T

    下一篇: 如何找到Javascript语法错误