What are the best JavaScript code programming practices? This may be a difficult question to answer. So, let’s change the question, what coding standards are the most popular?
sideeffect.kr came up with some interesting results by analyzing open source code hosted on GitHub. Let’s take a look.
Comma at the end of the line versus comma at the beginning of the line
Quotation mark at the end of the line:
Spaces and Tabs
Everyone loves to use spaces these days. Using space indentation can ensure that different developers and different editor settings see the same results.
Space, 81.1%; Tab, 18.9%. (Based on 2,019,550 submissions.)
Whether to add spaces after the function
No spaces
Is there a space between the parameters and the brackets?
No space
Is there a space around the colon in the object literal?
Is there a space after the colon? > The code is as follows:
Copy code
The code is as follows:
Single quotation mark, double quotation mark
Single quotation mark, 56.791%; double quotation mark, 43.209%. (Based on 1,705,910 submissions.)
Summary
So, the most popular code specification is:
• Comma at end of line
• Space indentation
• No space after function name
• No space between function parameters and parentheses
• Colon after object literal Space, do not add
before colon • Add space after conditional statement keyword
What is popular is not necessarily good (such as influenza), but from a communication perspective, writing code in a popular style can make your code look more familiar to most people.