Home > Article > Web Front-end > Summary of examples of the most powerful JavaScript naming methods
javascript has three classic variable naming methods: Hungarian nomenclature, camel case nomenclature and Pascal nomenclature.
Rules:
Variable names are case-sensitive and are allowed to contain letters, numbers, dollar signs ($), and underscores, but the first character is not allowed It is a number, and spaces and other punctuation marks are not allowed
The variable naming length should be as short as possible, and the key points should be grasped, and the type of value should be reflected in the variable name as much as possible
Try to avoid using meaningless names
It is forbidden to use JavaScript keywords and reserved full names
Common variable name naming methods include Hungarian nomenclature, camel case nomenclature and Pascal nomenclature
##Hungarian nomenclature
Syntax
Variable name = type + object descriptionTips
Although javascript variables do not have types on the surface, javascript will still assign corresponding types to variables internally. The Hungarian nomenclature was invented by a Microsoft programmer. Most c and c++ programs use this nomenclature.Example
##
var aName = [1, 2, 3]; var oBtn = document.getElementById('btn'); function fnName(){}; var iCount = 0; var sName = "zhuyujia";
Camel case
When variable names and function names are unique identifiers formed by linking two or more words together, use "camel case" to express them, which can increase the readability of variables and functions. sex.
"The term Camel-Case comes from the mixed case format commonly used in the Perl language, and the best-selling book "Programming Perl" (Published by O'Reilly) written by Larry Wall et al. The cover picture is a camel. "
The "camel case" naming rule can be regarded as a convention, not absolute or mandatory, in order to increase recognition and readability. Once you choose or set up a naming convention, you should maintain a consistent format when writing your program.
GrammarThe variable name or function name is composed of one or more words connected together, where the first word starts with a lowercase letter, and all subsequent words are The first letters are all capital letters, so the variable name looks like a camel's hump, hence the name.
Example##
var myName = "zhuyujia"; var formSubmit = document.getElementById("submit"); function timeCount(){}
Pascal nomenclature (Pascal Case, Pascal nomenclature/Pascal nomenclature), a set of naming rules (conventions) when writing computer programs.
Syntax
is similar to camel case, except that the first letter of the first word needs to be capitalized.
Example
var myName = "zhuyujia"; var formSubmit = document.getElementById("submit"); function timeCount(){}
The above is the detailed content of Summary of examples of the most powerful JavaScript naming methods. For more information, please follow other related articles on the PHP Chinese website!