In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "what are the JavaScript code specifications?". In the operation of actual cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
All JavaScript projects apply the same specification.
Code specifications usually include the following aspects:
Naming rules for variables and functions.
Rules for the use of spaces, indentation, and comments.
Other commonly used specifications.
Canonical code can be easier to read and maintain.
Code specifications are generally specified before development, and you can negotiate settings with your team members.
It is recommended to use the hump method to name the variable name (camelCase):
You need to add spaces before and after the operator (= +-* /):
Use 4 space symbols to indent the code block:
Using the TAB key for indentation is not recommended because the parsing of the TAB key varies from editor to editor.
General rules for simple statements:
A statement usually ends with a semicolon.
General rules for complex statements:
Place the left curly bracket at the end of the first line.
Add a space before the left curly bracket.
Place the right curly braces on a separate line.
Don't end a complex statement with a semicolon.
Rules defined by the object:
Put the left curly braces on the same line as the class name.
There is a space between the colon and the attribute value.
Strings use double quotation marks, numbers are not required.
Do not add a comma after the last attribute-value pair.
Http://www.iis7.com/b/wzjk/
Place the right curly braces on a separate line with a semicolon as the closing symbol.
Short object code can be written directly on one line:
It is recommended to have less than 80 characters per line for ease of reading.
If a JavaScript statement is more than 80 characters, it is recommended to wrap after the operator or comma.
Naming rules:
In general, many code languages have similar naming rules, such as:
Variables and functions are identified by the small hump method, that is, the first letter of the word is capitalized (lowerCamelCase) except for the first word.
Global variables are uppercase (UPPERCASE).
Constants such as PI are uppercase (UPPERCASE).
Do you use these rules for variable naming: hyp-hens, camelCase, or under_scores?
The horizontal bar (-) character of HTML and CSS: it is usually considered subtraction in JavaScript, so it is not allowed.
The HTML5 attribute can be prefixed with data- (for example: data-quantity, data-price).
CSS uses-to connect the property name (font-size).
Underline:
Many programmers prefer to use underscores (such as date_of_birth), especially in SQL databases.
The PHP language usually uses underscores.
Pascal spelling (PascalCase):
Pascal spelling (PascalCase) has many languages in C language.
Hump method:
The hump method is usually recommended in JavaScript. JQuery and other JavaScript libraries use the hump method.
The variable name should not be marked with $as it will conflict with many JavaScript libraries.
HTML loads external JavaScript files and loads JavaScript files in a concise format (the type attribute is not required): for example
File extension:
The HTML file suffix can be .html (or r. HTM).
The CSS file suffix is .css.
The JavaScript file suffix is .js.
Use lowercase file names:
Most Web servers (Apache, Unix) are case-sensitive: london.jpg cannot be accessed through London.jpg.
Other Web servers (Microsoft, IIS) are case-insensitive: london.jpg can be accessed through London.jpg or london.jpg.
You must maintain a uniform style, and we recommend using lowercase file names.
This is the end of "what are the JavaScript Code specifications?" Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.