Javascript tool-use jslint to check JavaScript syntax

Source: Internet
Author: User

Jslint is a javascript verification tool (www.jslint.com) that can scan JavascriptSource codeTo find the problem. If jslint finds a problem, jslint will display a message describing the problem and point out the error in the sourceCode. Some encoding style conventions may cause unforeseen behaviors or errors. In addition to pointing out these unreasonable conventions, jslint can also mark structural problems. Although jslint cannot ensure that the logic is correct, it does help to identify errors, which may cause the JavaScript engine of the browser to throw errors.

Jslint defines a set of encoding conventions, which is stricter than the language defined by ECMA. These coding conventions draw on years of rich coding experience and take a long-standing programming principle as its purpose: Doing it does not mean doing it. Jslint adds a flag to the Code practices that it deems risky, and points out which are obvious errors (see Figure 5-12), so that you can develop good JavaScript coding habits.

Figure 5-12 jslint checks errors and bad encoding styles to provide JavaScript Verification

Jslint may mark some structural errors as suspicious encoding practices. Some of them are listed below (For a complete list, refer to the jslint documentation ).

L jslint requires that all code lines end with a semicolon. Although JavaScript does allow a line break as a line terminator, it is generally considered ambiguous and a bad encoding style.

L if and for statements must be enclosed in braces.

L different from otherProgramming LanguageIn JavaScript, blocks are not used as the scope of variables. 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. Other blocks are marked as errors.

L var can only be declared once, and must be declared before use.

L jslint marks the code that appears after the return, break, continue, or throw statements as unfeasible code. These statements must be followed by an ending braces.

For JavascriptProgramFor beginners, jslint is a very good tool because it will teach you some good JavaScript coding practices. Because jslint can mark parts that may cause logical errors or other unforeseen behaviors, debugging time can be reduced. If you encounter difficulties in debugging A JavaScript code, try jslint.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.