good example
age
myAge
init
initialColor
finalOutputValue
audio1
audio2
bad example
1
a
_12
myage
MYAGE
var
Document
skjfndskjfnbdskjfb
thisisareallylongstupidvariablenameman
rules
Generally, you should stick to just using Latin characters (0-9, a-z, A-Z) and the underscore character.
- Don’t use underscores at the start of variable names — this is used in certain JavaScript constructs to mean specific things, so may get confusing. 别以下划线开头
- Don’t use numbers at the start of variables. This isn’t allowed and will cause an error. 别以数字开头
- Using lower case for the whole first word and then capitalize subsequent words. We’ve been using this for our variable names in the article so far. 先小写再大写
- Variables are case sensitive — so myage is a different variable to myAge. JS对大小写敏感
- Avoid using JavaScript reserved words as your variable names. 别用JS关键字