HTML5 School: In JavaScript writing, variables are indispensable, each variable has its own name, code specification is particularly important. Small series here to summarize the three kinds of variable nomenclature, namely the Hungarian nomenclature, Camel/Hump nomenclature, Pascal named Law.
Hungarian Naming Act
It is said that this nomenclature was invented by a Hungarian programmer named Charles Simonyi, who later spent several years at Microsoft, and the nomenclature spread through Microsoft's various products and documentation. The starting point of this nomenclature is to combine variable names by: The Order of attribute + Type + object description, so that programmers have a visual understanding of variable types and other properties when they make variables.
The Properties section represents the overall properties of a variable, such as:
Global variables: g_
Constant: C_
Member Variable: m_
Static variable: s_
The type section represents the data type of the variable, for example:
Function: fn
Boolean value: b
String: str
Integral type: I
The object Description section represents the purpose of the variable, for example:
Max: Max
Min: Min
Temp variable: T
An example is given below:
var g_strusername = ' yard carpenter ';
var C_FPI = 3.14;
Camel-Named method
Camel-named method, also known as the small hump named, is the most commonly used in JavaScript identifier naming method. Camel-style nomenclature is when an identifier is concatenated with one or more words, the first letter is lowercase, the following words are capitalized, and the other letters are all lowercase. Example:
var webName = "code Carpenter";
Pascal name Law
Pascal's nomenclature is also called the Big Hump nomenclature, which is similar to camel-like nomenclature, except that camel-named is the first lowercase letter, while the first letter of the Pascal-named method is capitalized. Example:
var WebName = "code Carpenter";
Above we talked about JS three kinds of variable naming methods, namely the Hungarian nomenclature, camel-type nomenclature, Pascal named Law. We know that JavaScript is a language of weakly variable type, that is, a variable declared in JavaScript, which can be a data type, and then we can turn it into another data type, for example:
var a = "Code Carpenter";
Console.log (a); "Code Maker"
Console.log (typeof (a)); "String"
A = 123;
Console.log (a); 123
Console.log (a); "Number"
By observing the example above, the variable a starts out as a string type, and then a becomes a numeric type. So in JavaScript, where the data type requirements are not strict, there is little point in using the Hungarian nomenclature in JavaScript. When writing identifiers, it is common to use the Pascal nomenclature to name the constructor, while the camel-named method names other functions or other variables.
JS three classical variable naming method