JavaScript programming specification (continuous update ...)

Source: Internet
Author: User

Indent in

Each level consists of 4 spaces, avoiding the use of tab

Length of Line

Each line is not more than 80 characters long, and if one line is more than 80 characters, you should wrap the line after an operator (comma, plus, and so on). The next line should be increased by two levels of indentation (8 characters).

Original value

Strings always use double quotation marks (avoid using single quotes) and keep one line. Avoid using slashes in strings to start another line.

Numbers should use decimal integers. Scientific notation represents integers, hexadecimal integers, or decimal floating-point decimals, which should retain at least one digit before and after the decimal point. Avoid using octal direct quantities.

Special value NULL should be avoided except in the following cases.

A) is used to initialize a scalar, which may be assigned to an object.

b) is used to compare with an already initialized variable, which can or may not be an object.

c) When the function's parameter is expected to be an object, it is used as a parameter pass in.

D) When the return value of a function is expected to be an object, it is used as the return value for outgoing.

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

operator spacing

A space must be used before and after a binary operator to keep the expression neat. Operators include assignment operators and logical operators.

Spacing between brackets

When parentheses are used, there should be no spaces immediately after the opening parenthesis and immediately before the closing parenthesis.

The direct amount of the object should use the following format

A) the start-left curly brace should remain on the same line as the expression.

b) The name value pair (Key-value) for each property should be indented, and the first attribute should be followed by a row after the left curly brace.

c) The name value pair (Key-value) for each property should use a property name that is not quoted, followed by a colon (with no spaces before it), and then a value.

d) If the attribute value is a function type, the function body should have a row below the property name, and it should keep a blank line before and after it.

e) A set of related attributes can be inserted before and after a blank line to improve the readability of the code.

f) The closing curly brace should be exclusive on one line.

g) When the object literal is a function parameter, if the value is a variable, the starting curly brace should be the same line as the function name. All the remaining previously listed rules also apply.

Comments

Frequently apply comments to help others understand your code. Comments should be used as follows.

A) The code is obscure and difficult to understand.

b) Code that may be mistaken for errors.

c) necessary, but not obvious, browser-specific code.

d) For objects, methods, or properties, it is necessary to generate the document (using appropriate documentation comments).

Single-line Comment

A single-line comment should be used to describe a line of code or a set of related code. There are three possible ways to use a single line of comments.

A) An exclusive line of comments to explain the next line of code.

b) A comment at the end of the line of code used to explain the code before it.

c) Multiple lines, which are used to comment out a block of code.

For a line-of-code comment, ensure that at least one indentation is made between the end of the code and the comment.

Note A code block is the only acceptable case where a single line of comments is used for successive lines. Multi-line annotations should not be used in this case.

JavaScript programming specification (continuous update ...)

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.