In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Most people do not understand the knowledge points of this article "what are the rules for naming variables in javascript", so the editor summarizes the following, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "what are the rules for naming variables in javascript".
Rules for naming variables: 1. Variable names are case-sensitive and are allowed to include numbers, letters, underscores "_" and the dollar sign "$". But the first character cannot be a number; 2. Chinese characters, spaces, hyphens "-", dots "cannot appear in variable names." And other special characters; 3, variable names can not be keywords, reserved words; 4, avoid using meaningless naming and so on.
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
Variables are one of the foundations of all programming languages and can be used to store data, such as strings, numbers, Boolean values, arrays, and so on, and to set, update, or read the contents of variables as needed. We can think of a variable as the symbolic name of a value.
Naming rules for variables in javascript
In JavaScript, variable names cannot be defined casually, and you need to follow the naming rules for identifiers:
Variable names are case-sensitive and are allowed to contain numbers, letters, underscores _, and the dollar sign $, but cannot start with a number, that is, the first character cannot be a number.
Chinese characters, spaces, hyphens (-) and dots (.) cannot appear in variable names. Special characters such as number.
Variable name cannot be a keyword or reserved word in JavaScript
The length of variable naming should be as short as possible, and grasp the main points, as far as possible to reflect the type of information stored in the variable name.
Try to avoid using meaningless naming
When defining a variable, the variable name should be as meaningful as possible so that it can be easily understood by yourself or others. For example, you can use name to define a variable to store the name, and dataArr to define an array type variable.
When the variable name contains multiple English words, it is recommended to use the hump naming method (big hump: the first letter of each word is capitalized, such as FileType, DataArr; hump: the first letter of the first word is capitalized after lowercase, such as fileType, dataArr).
The common naming methods of variable names are Hungarian naming, hump naming and Pascal naming.
Hungarian nomenclature
Hungarian nomenclature is a kind of variable naming rule in computer programming, which can be subdivided into systematic Hungarian nomenclature and Hungarian application nomenclature.
Hungarian nomenclature is language independent and is widely used in BCPL for the first time. Because BCPL has only one data type, machine words, the language itself does not help programmers remember the types of variables. The Hungarian nomenclature solves this problem by specifying the data type of each variable.
In Hungarian nomenclature, a variable name begins with one or more lowercase letters that help you remember the type and purpose of the variable, followed by any name chosen by the programmer. The first letter of the second half can be capitalized to distinguish the preceding type indicator letter.
Grammar
Variable name = type + object description
Type refers to the type of variable
Object description refers to the full name or part of the name of the object, which is required to have a clear meaning, and the naming should be easy to remember and understand.
The type of the variable is indicated by prefixing the symbol of the corresponding lowercase letter to the variable name, followed by a combination of one or more words that describe the purpose of the variable. If it is a jquery object, use $as the prefix for the variable name.
Prompt
Although there is no type on the surface of the javascript variable, the corresponding type is assigned to the variable internally in javascript.
The Hungarian nomenclature was invented by a Microsoft programmer and is used by most cMagnec programs.
Types
Javascript variable naming type variable naming prefix array array aboolean Boolean value bfloat floating point lfunction function fnint integer iobject object oregular regular rstring string s
Example
Var aName = [1,2,3]; var oBtn = document.getElementById ('btn'); function fnName () {}; var iCount = 0polivar sName = "zhuyujia"
Hump nomenclature
When the variable name and function name are unique identifiers formed by two or more words linked together, the use of "hump case" can increase the readability of variables and functions.
"the word Camel-Case comes from the mixed case format commonly used in the Perl language, and the cover picture of Larry Wall et al's best-selling book Programming Perl (published by O'Reilly) is a camel."
The "hump case" naming rule can be regarded as a convention, not absolute or mandatory, in order to increase identification and readability. Once the naming rules are selected or set, you should maintain a consistent format when writing the program.
Grammar
Variable names or function names are linked by one or more words, the first word begins with a lowercase letter, and all subsequent words begin with uppercase letters, so the variable name looks like a camel hump. Hence the name.
Example
Var myName = "zhuyujia"; var formSubmit = document.getElementById ("submit"); function timeCount () {}
Pascal nomenclature
Pascal naming method (Pascal Case, Pascal naming method / Pascal naming method), a set of naming rules (conventions) for computer programming.
When the variable name and function name are unique identifiers formed by two or more words linked together, it is used to increase the readability of variables and functions.
Words are not broken by spaces or linked with a connection sign (-) or underscore (_). The first single prefix letter is capitalized, and the first letter of subsequent words is also capitalized, such as FirstName, LastName. The first letter of each word is named in uppercase format, which is called "Pascal nomenclature". It is derived from the naming convention of Pascal language, and some people call it "great hump nomenclature" (Upper Camel Case), which is a subset of hump capitalization.
Pascal nomenclature can be regarded as a naming convention, not absolute or mandatory, in order to increase identification and readability. Once the naming rules are selected or set, the format should be consistent when writing the program.
Grammar
Similar to hump naming, except that the first letter of the first word needs to be capitalized.
Example
Var MyName = "zhuyujia"; var FormSubmit = document.getElementById ("submit"); function TimeCount () {} above is the content of this article on "what are the rules for naming variables in javascript?" I believe you all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.