Home > Article > Web Front-end > What must a variable start with javascript
In JavaScript, giving a variable a name (variable naming) must start with a letter, underscore, or dollar sign; it is case-sensitive; JS keywords or reserved words are not allowed.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
In order to distinguish boxes, we can use names such as BOX1 and BOX2 to represent different boxes. BOX1 is the name of the box (that is, the name of the variable).
Let’s quickly give the variable a good name! The variable name can be chosen arbitrarily, but the name must follow some rules:
1. It must start with Begins with a letter, underscore, or dollar sign, and can be followed by letters, underscores, dollar signs, and numbers. As follows:
正确: mysum _mychar $numa1
错误: 6num //开头不能用数字 %sum //开头不能用除(_ $)外特殊符号,如(% + /等) sum+num //开头中间不能使用除(_ $)外特殊符号,如(% + /等)
2. Variable names are case-sensitive, for example: A and a are two different variables.
3. JavaScript keywords and reserved words are not allowed to be used as variable names.
[Recommended learning: javascript advanced tutorial]
The above is the detailed content of What must a variable start with javascript. For more information, please follow other related articles on the PHP Chinese website!