Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the coding specifications of the JavaScript programming language

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you what the coding specifications of the JavaScript programming language are, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Recommendations for JavaScript coding specifications

Based on the summary of personal study and work, this paper gives some suggestions on the typesetting, naming, declaration, scope and the use of some special symbols involved in the JavaScript coding process, and analyzes the reasons for reference.

JavaScript file referenc

JavaScript programs should be kept in .js files as much as possible, and should be included in HTML when needed. If the JavaScript code is not specific to the HTML file, you should try to avoid writing JavaScript code directly in the HTML file. Because this will greatly increase the size of the HTML file, it is not conducive to code compression and cache use.

In addition, the label should be placed at the back of the file as far as possible. This reduces the load time of other components on the page due to loading JavaScript code.

Code typesetting line length

Each line of code should be less than 80 characters. If the code is long, try to choose a line break, and the next line of code should be indented by 8 spaces. This makes the code neatly typeset and reduces the fatigue of reading the code. Newline indentation of 8 spaces can be distinguished from code snippet indentation of 4 spaces to enhance the readability of the code.

End of line

The JavaScript statement should end with a semicolon. But most browsers allow you not to write a semicolon, as long as there is a newline where it is supposed to be. But if the line of code is long and needs to be wrapped, what are the considerations? Line breaks should be chosen after operators and punctuation, preferably after commas',', rather than after symbols such as variable names, strings, numbers, or')'+ +'-'.

This can effectively prevent errors caused by copying and pasting, and can effectively enhance the readability of the code. The output of the code meets our expectations. However, as far as writing is concerned, the assignment statement to valueB is a line wrap after the variable valueA, which can easily be misunderstood as valueB=ValueA, causing obstacles to reading. The copy statement for valueC is a line wrap after'+', which is much easier to understand. This is also the way of line wrapping advocated in this article.

These are all the contents of this article entitled "what are the coding specifications of the JavaScript programming language?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report