JS naming rules: Hungarian or camper naming rules

Source: Internet
Author: User
Naming Conventions are necessary to enhance the readability of the Code, so that you can understand what you want to express at a Glance. Standards are rules that make the code easier for later maintenance, it can also greatly improve the development efficiency.

JS naming rules

Naming Conventions are necessary to enhance the readability of the Code, so that you can understand what you want to express at a Glance. Standards are rules that make the code easier for later maintenance, it can also greatly improve the development efficiency. A normal website has a lot of JS Code. If you do not follow certain rules during the compilation process, you will not be able to understand what you wrote after writing it. This is a very troublesome thing, therefore, we need to develop a good habit of writing code during regular exercises.

Generally, the Hungarian or camper method is used.

The principle of the Hungarian naming method: variable name = property + Type + object description. The key is to use one or more lower-case letters as the prefix, followed by a combination of one or more upper-case words, which indicates the purpose of the variable.

The first word starts with a lowercase letter, and then the first letter of each word is capitalized. For example, myFirstName and myLastName, the variable name looks like a camper. The key to the hump method is: in addition to the first word, the size of the first letter of other words. The variable name and function name are composed of uppercase and lowercase letters, and the logical breakpoint can be formed by underlines, this improves the readability of the Code.

What naming conventions should be based on personal preferences or company regulations. Note: you cannot use reserved words or names that are too long to remember. Avoid using two similar variable names. The following are the prefixes of commonly used Hungarian naming methods:

Type Prefix Type Instance
Array A Array AItems (Project)
String S String SUserName
Function Fn Function FnHandler (Processing Program)
Object O Object Op
Integer I Integer IItemCount (Project count)
Floating Point Number F Float FPrice)
Boolean Value B Boolean BIsComplete (completed)
Regular Expression Re RegExp ReEmailCheck (email detection)

The above is the JS naming convention: details of the Hungarian or camper method. For more information, see other related articles in the first PHP community!

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.