JSLint is a JavaScript verification tool (Www.jslint.com) that scans JavaScript source code to find problems. If JSLint finds a problem, JSLint displays a message that describes the problem and points out the approximate location of the error in the source code. Some coding style conventions may lead to unforeseen behavior or errors, and JSLint can mark out structural problems in addition to the unreasonable conventions. Although JSLint does not guarantee that the logic must be correct, it does help to discover errors that are likely to cause the browser's JavaScript engine to throw errors.
JSLint defines a set of coding conventions that are more restrictive than the language defined by ECMA. These coding conventions draw on the rich coding experience of many years and use an age-old programming principle as a tenet: being able to do doesn't mean you should. JSLint will flag code practices that it considers risky, and it will also point to obvious errors (see figure 5-12), prompting you to develop good JavaScript coding habits.
Figure 5-12 JSLint will check for errors and bad coding styles to provide JavaScript validation
JSLint may have identified some structural errors as questionable coding practices, some of which are listed below (the complete list can refer to JSLint's documentation).
JSLint requires that all lines of code end with semicolons. Although JavaScript does allow newline characters to be used as a line terminator, it is generally considered ambiguous and a bad coding style.
Statements using if and for are required to enclose the block of statements using curly braces.
Unlike other programming languages, in JavaScript, a block is not scoped to a variable. JavaScript only supports function-level scopes. Therefore, JSLint only accepts blocks that are part of the function, if, switch, while, for, do, and try statements, and all other blocks are flagged as errors.
var can only be declared once, and must be declared before it is used.
JSLint the code that appears after the return, break, continue, or throw statement as an unreachable code. These statements must be followed by an end brace.
JSLint is a great tool for JavaScript programmers as a novice, because it teaches you some good JavaScript coding practices. Because JSLint can label parts that may cause logical errors or other unforeseen behavior, you can reduce debugging time. If you have trouble debugging a piece of JavaScript code, try JSLint.
Back to "Ajax Basics Tutorial-Directory"