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关键字
本文详细介绍了JavaScript中变量命名的最佳实践,包括使用拉丁字符、避免下划线和数字开头、采用驼峰命名法以及区分大小写的重要性。同时,文章强调了避免使用保留字作为变量名的必要性。
607

被折叠的 条评论
为什么被折叠?



