来源 :http://www.codelifter.com/main/tips/tip_020.shtml

The following are the rules for naming JavaScript variables:

1.
A variable name cannot start with a numeral. For instance, 3x or
2goats or
76trombones would all be
illegal variable names.

You can, however, have numbers within a JavaScript variable name; for instance
up2me or
go4it would both be perfectly valid variable names.

不能以数字开头

2.
You cannot have a mathematical or logical operator in a variable name. For instance,
2*something or
this+that would both be illegal... because the * and the + are arithmetic operators. The same holds true for ^, /, \, !, etc.

变量名中不能含有操作符

3.
You must not use any punctuation marks of any kind in a JavaScript variable name, other than the
underscore; for example... some:thing or
big# or
do'to would all be
illegal.

The underscore is the exception, and it can be used at the beginning, within, or at the end of JavaScript variable names. You can use names like
_pounds or
some_thing or
gallons_ as variable names and they are perfectly legal.

变量名中不能有标点符号,除了_下划线以外的任何标点符号。

4.
JavaScript names must not contain spaces. Ever.

变量名中不能有空格

5.
You cannot use JavaScript keywords (parts of the language, itself) for variable names. Thus
window or
open or
location
or string
would be illegal.  Check a JavaScript reference if in
doubt as to whether something is or is not part of the language --
JavaScript has grown into a fairly fully-fleshed language, so you
may get some occasional surprises.

You can, of course, use what are otherwise keywords as parts of variable names. For instance,
thatWindow or
someString or
theLocation would all be perfectly acceptable.

变量中不能用JavaScript语言的关键词。如 window,string,blooean等等

6.
JavaScript variable names are case-sensitive. Programmers in other languages are often tripped up by this one, as some languages are not sensitive to case in variable names.

For instance, all of the following names would be considered completely different variable names in JavaScript: 
gasbag 
Gasbag  GasBag  gasBag

变量名区分大小写.

总结:

通常情况下变量名只能由大小写的英文字母和数字组成, 即A-Z a-z  0-9构成

只能以字母或者下划线开头。

不能包含特殊字符,不能用关键词作变量名。

-----------欢迎补充

JavaScript 命名规则的更多相关文章

  1. javascript命名规则

    javascript对大小写敏感(关键字.函数名.变量名等),标识符的首字符必须是字母.下划线或者$符,其后的字符可以含数字 如果之声明了变量,并未对其赋值,默认为undefined javascri ...

  2. JavaScript 基础(一) - JavaScript的引入方式,JavaScript 变量命名规则,JS 的五种基本数据类型,ECMAScript 算数运算符,逻辑运算符

    JavaScript的引入方式 直接编写 <!DOCTYPE html> <html lang="en"> <head> <meta ch ...

  3. javascript中变量命名规则

    前言 变量的命名相对而言没有太多的技术含量,今天整理有关于变量命名相关的规则,主要是想告诉大家,虽然命名没有技术含量,但对于个人编码,或者说一个团队的再次开发及阅读是相当有用的.良好的书写规范可以让你 ...

  4. javascript对象属性的命名规则

    JS标识符的命名规则,即变量的命名规则: 标识符只能由字母.数字.下划线和‘$’组成 数字不可以作为标识符的首字符 对象属性的命名规则 通过[]操作符为对象添加属性时,属性名称可以是任何字符串(包括只 ...

  5. [No00009E]几种常见的命名规则

    变量命名规则 必须遵循的命名规则 1.    变量名首字母必须为字母(a-z A-Z),下划线(_),或者美元符号($)开始php编程中所有变量必须以$开始. 2.    变量名只能是字母(a-z A ...

  6. CSS书写规范、顺序和命名规则

    写了这么久的CSS,但大部分前端er都没有按照良好的CSS书写规范来写CSS代码,这样会影响代码的阅读体验,这里总结一个CSS书写规范.CSS书写顺序供大家参考   这些是参考了国外一些文章以及我的个 ...

  7. 翻译:Identifier Name标识符命名规则

    */ .hljs { display: block; overflow-x: auto; padding: 0.5em; color: #333; background: #f8f8f8; } .hl ...

  8. [ExtJS5学习笔记]第六节 Extjs的类系统Class System命名规则及定义和调试

    本文地址: http://blog.csdn.net/sushengmiyan/article/details/38479079 本文作者:sushengmiyan ----------------- ...

  9. CSS命名规则常用的css命名规则

    CSS命名规则常用的css命名规则 头:header 内容:content/container 尾:footer 导航:nav 侧栏:sidebar 栏目:column 页面外围控制整体布局宽度:wr ...

随机推荐

  1. Project Woosah Tu (五色土)

    I bought this Raspberry Pi (model B) in spring 2013, I hadn't done too much with it except for some ...

  2. forEach遍历数组实例

    forEach()取出数组中2的倍数和3的倍数的数 //for IE if(!Array.prototype.forEach){ Array.prototype.forEach = function( ...

  3. 我的第一份供lua调用的c模块

    #include <stdio.h> #include <string> #include <direct.h> #include <windows.h> ...

  4. Linux 压缩和解压缩常用命令

    主要记录tar,zip,gzip,bzip2,rar等常用命令,对.tar..gz..tar.gz..tgz..bz2..tar.bz2..zip..rar这8种压缩文件的操作. 1. tar 命令 ...

  5. js之路

    开始记录js学习: udacity,edx上不去: 搞了一个html+css+JavaScript后开始看es6; 犀牛书,js启示录,你不知道的js上中: 第一个库jQuery及源码分析: --

  6. WebView 载入本地的html

    1.可以是用loadData,这种方法需要先将html文件读取出来,以字符串传入loadData,可以展示页面,但是不会引用css.js等文件. 2.使用loadUrl,不过需要注意,这里因为是使用本 ...

  7. IDEA IntelliJ常用设置以及快捷键(转)

    转载自:http://macrochen.iteye.com/blog/1035680 关于字体的设置 IDEA下使用雅黑Consolas混合字体      快捷贱, 快捷贱 , 快捷键贱    In ...

  8. WIN7 WIN8 WIN10你们的WmiPrvSE.exe系统占用资源厉害吗?

    大家一起来做个实验吧.把你的支付宝安全控件和支付宝数字证书两个东东都卸掉.试试看电脑是否年轻几岁? 出处:百度贴吧原帖

  9. [转]使用Maven添加依赖项时(Add Dependency)时,没有提示项目可用,并且在Console中,输出: Unable to update index for central|http://repo1.maven.org/maven2 。

    使用Maven添加依赖项时(Add Dependency)时,没有提示项目可用,并且在Console中,输出: Unable to update index for central|http://re ...

  10. .net frameworkAPI文档下载地址

    http://www.msdn.hk/html/2014/5.html VS2013 ILdasm 反编译工具安装在下面地址里了 C:\Program Files (x86)\Microsoft SD ...