JavaScript programming Style-basic formatting

Source: Internet
Author: User

The indent level recommends 4 space characters as an indent level. It is recommended not to omit semicolons at the end of a statement. The length of the line should be no more than 80 characters long. NewLine wraps after the operator, and the next line adds two levels of indentation. Exception: When assigning a value to a variable, the position of the second row is aligned with the position of the assignment operator. For example:
var result = something + anotherThing + yetAnotherThing + somethingElse + anotherSomethingElse;A blank line is named between a method's local variable and the first statement in a method before a multiple-line or single-line comment is a camel case: starts with a lowercase letter, Capitalize the first letter of each subsequent word. Variables and function variable name prefixes should be nouns, before function names should be verbs. var count = 10; var myName = "Nick"; var found = true;   function getName(){ return myName; }
Border Meaning
Can function returns a Boolean value
Has function returns a Boolean value
Is function returns a Boolean value
Get function returns a non-Boolean value
Set function to hold a value
Constants are named with uppercase letters and underscores, and underscores are used to separate words.    Constructor large hump naming method, starting with capital letters. Benefits: Following this convention, a function named after the big Hump is a noun, there must be a new operator in front of it.    Direct volume string single and double quotation marks can be, only need to maintain a style from beginning to end, if you switch frequently in Java and JavaScript, it is recommended to use double quotation marks. Multi-line string notation: Use a string connector (+) to tell a string into multiple copies. //Good var longString = "Here‘s the story of a man " + "named Brady.";   //这是一种奇技淫巧而非语言特性。在Google的JavaScript风格指南中是禁止的。 var longString = "Here‘s the story of a man \ named Brady.";Numbers do not omit parts before or after the decimal point. Don't write octal.        Null is used to initialize a variable and may be assigned to an object.        Used to compare to an already initialized variable, which can or might not be an object.        Used as a parameter when the function's parameters are expected to be an object. When the return value of a function is expected to be an object, the return value is used as outgoing.        The following scenario does not use NULL to not use NULL to detect whether a parameter was passed in. Do not use NULL to detect an uninitialized variable. Undefined avoid using undefined, you can effectively ensure that typeof returns "undefined" only in one case. The direct amount of the object encloses all the attributes in a pair of curly braces. The first line contains the left curly braces, and each property has a single row for the name value, and one indentation, and the last closing curly brace also takes up a row. The data direct volume is enclosed in two square brackets for the initial element of the data.

JavaScript programming Style-basic formatting

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.