Front End (HTML/CSS/JS)-javascript Coding specification

Source: Internet
Author: User

1. Variable naming (1) Variable names should not be proud of a short coincidence

The variable name on the left is not very clear, the code extensibility is not good, once the code needs to add functionality, it is easy to appear obj1, Obj2, obj3 this very abstract naming method. So start by making the name of the variable really meaningful, and don't make a very short, generic name.

(2) BOOL variable

It is not advisable to start with a Boolean variable like is/do

var true ,     true ,     false;

Can be changed into:

var true ,     true ,     false;

There are other commonly used names such as Done/found/successs/ok/available/complete and so on, combined with specific contexts

var true ,     false ,     true;
2. Assigning a value when declaring a variable

Declaration of three variables as follows

var Registerform,     question,     calculateresult;

The above is definitely the legal JS syntax, but the use of these three variables will make people more confused, especially in the middle of the second question, the question is what. But when you assign an initial value to the above variable:

var NULL ,      = "",     = 0;

Let the person be enlightened, originally question is a string of questions, and result is a number, and form is an object. This also facilitates the JS interpreter to do some optimization in advance, do not wait until the use of the time to know what these variables are type

Front End (HTML/CSS/JS)-javascript Coding specification

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.