JavaScript Coding Style

Source: Internet
Author: User

  1. Indent in
    The hierarchy of each row consists of 4 spaces
  2. Length of Line
    Each line is not more than 80 characters long. If a row exceeds 80 characters, wraps after an operator (comma, plus sign), and the next line increments by 2 indents
  3. Original value
    Avoid using special value undefined to determine whether a variable is defined with the TypeOf operator
  4. Comments
    A) an exclusive line of comments to explain the next line of code;
    B) a comment at the end of the code line to explain the code before it;
    C) multiple lines, used to comment out a code
    /**/
  5. Strict mode
    Strict mode should be used inside the function, never in the global use
    // Good wording. function dosomething () {    "usestrict";     // Code     }

    You can use a function that is called immediately if you expect strict mode to be used in multiple functions without declaring "use strict" multiple Times.

      (function () {  " use Strict  "  ; function dosomething () { //  code } function dosomethingelse () { // code  }} ());  
  6. equals operator
    Avoid type conversion errors using = = = (strictly Equal) and!== (strictly unequal) instead of = = (equal) and! = (unequal)
    if (a===b) {    //  Code }


JavaScript Coding Style

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.