The best JavaScript code specifications Tutorial In 2024, In this tutorial you can learn JavaScript code specifications,variable name,Space and the operator,Code indented,Statements Rule,Object Rule,Less than 80 characters in each line of code,Naming Rules,HTML load external JavaScript files,Use JavaScript to access HTML elements,File extension,Lowercase filenames,
All JavaScript project applies the same specification.
Code specifications generally include the following aspects:
Standardized code easier to read and maintain.
Codes of general provisions in the development of the former, you can with your team members to negotiate the setting.
Variable names recommended method camel named (camelCase):
Typically operator (= + - * /) to add a space before and after:
Symbols typically use four spaces to indent a block of code:
Not recommended to use the TAB key to indent, as different editors TAB key is not the same resolve. |
Simple statements of general rules:
General rules for complex statement:
Object-defined rules:
Short object code can be written directly to the line:
For ease of reading recommend less than the number of characters per line 80.
If a JavaScript statement is more than 80 characters, it is recommended after the comma operator or wrap.
Usually a lot of code language naming rules are similar, for example:
Variable name you use these types of rules: hyp-hens, camelCase, or under_scores?
HTML and CSS dash (-) characters:
HTML5 attribute may data- (such as: data-quantity, data-price) as a prefix.
CSS uses - to connect the property name (font-size).
- Generally considered a subtraction in JavaScript, it is not allowed. |
Underline:
Many programmers prefer to use an underscore (eg: date_of_birth), especially in the SQL database.
PHP language usually use underscores.
Pascal spelling (PascalCase):
Pascal spelling (PascalCase) in C language more.
Hump law:
JavaScript is usually recommended hump method, jQuery and other JavaScript libraries use camel law.
Variable names do not begin with $ mark conflicts with a lot of JavaScript libraries. |
Use simple format to load JavaScript file (type attribute is not required):
A bad HTML format may cause the execution of JavaScript errors.
The following two JavaScript statements to output different results:
HTML and JavaScript try to use the same naming rules.
Access HTML (5) code specifications .
HTML file suffix can be (or r .htm).
CSS file extension is .css.
JavaScript file suffix .js.
Most Web servers (Apache, Unix) are case sensitive: london.jpg London.jpg can not access.
Other Web servers (Microsoft, IIS) is not case sensitive: london.jpg can be accessed via London.jpg or london.jpg.
You must maintain a unified style, we recommend consistent use lowercase file names.