Writing maintainable JavaScript reading notes (appendix A): JavaScript Coding style Guide (1) original value

Source: Internet
Author: User

Document the more useful coding specifications (the guidelines are based on the Java language encoding specification and JAVASCRIPT programming specifications, combined with the personal experience and preferences of the author Nicholos Zakas).

Some specifications for formatting (including indentation, line length, operator spacing, bracket spacing, object Direct volume, comments, single-line comments, multiline annotations, and so on) are not recorded here.

A.3 Original Value

   var name = "Nicholos"//var name = ' Nicholos '  //  var longstring = "Here's the story, of a man named Brady.";

Special value NULL should be avoided in addition to the following conditions.

① used to initialize a variable

② is used to compare to an already initialized variable, which can or may not be an object

③ when a function's argument is expected to be an object, it is used as a parameter passed in

④ when the return value of a function is expected to be an object, it is used as the return value outgoing

For example:

//good wording.varperson =NULL;//good wording.functiongetperosn () {if(condition) {return NewPerson ("Nicholas"); } Else {        return NULL; }    }//good wording.varperson =getperosn ();if(Person!==NULL) {dosomething (); }//bad notation: compare to an uninitialized variablevarPerson ;if(Person! =NULL) {dosomething (); }//bad writing: test to determine whether a parameter is passedfunctiondosomething (arg1, arg2, Arg3, Arg4) {if(Arg4! =NULL) {dosomethingelse (); }}

Avoid using special value undefined. Determine if a variable should be defined using the TypeOf operator.

// good wording. if (typeof variable = = "undefined")    {//dosomething}//  Bad wording: Using the undefined direct volume if (variable = = undefined) {    //dosomething }

Writing maintainable JavaScript reading notes (appendix A): JavaScript Coding style Guide (1) original value

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.