来源 :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. 玩玩cordova(MAC安装环境)

    PhoneGap/cordova为代表的基于HTML5开发iOS/Android应用的技术,大大降低了手机App的开发门槛.虽然目前与原生的Object-C/Java开发的应用在性能上还有差距,但是对 ...

  2. dede currentstyle属性完美解决方案

    问题一.dede让channelartlist标签支持currentstyle属性 完美解决 打开include\taglib\channelartlist.lib.php找到$pv->Fiel ...

  3. JSWindow对象

    Window 对象 Window 对象表示浏览器中打开的窗口. 如果文档包含框架(frame 或 iframe 标签),浏览器会为 HTML 文档创建一个 window 对象,并为每个框架创建一个额外 ...

  4. 模块:js实现一个倒计时功能

    1.给显示内容加样式 <style> #p1{font-size: large; color: red;} </style> 2.客户端页面 <div id=" ...

  5. URL Scheme APP跳转safari以及跳回APP

    上图 : 在plist文件里面设置. URL identifier 一般为反域名+项目名称 (尽可能保证少重复) URL Schemes是一个数组.一个APP可以添加多个.该参数为跳转时使用的标识. ...

  6. 关于vue.js中列表渲染练习

    html: <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8 ...

  7. mac快捷键

    切换 1. 应用程序切换 command tab 2.应用程序中的窗口间切换 command ~ ===================== 通用 1. 隐藏窗口 command H 2. 最小化窗口 ...

  8. 针对web高并发量的处理

    针对web高并发量的处理 针对高并发量的处理 一个老生常谈的话题了 至于需要运维支持的那些cdn.负载均衡神马的就不赘述了 你们都懂的 虫子在此博文只讲一些从程序角度出发的一些不错的解决方案. 至于从 ...

  9. List的FindIndex和ForEach

    FindIndex和ForEach能接受一个delegate,用来定义查找规则太好用. 匿名函数,萌萌哒:Conditional("DEBUG")也是极好的. 读<C#本质论 ...

  10. .NET中的动态编译

    代码的动态编译并执行是一个.NET平台提供给我们的很强大的工具用以灵活扩展(当然是面对内部开发人员)复杂而无法估算的逻辑,并通过一些额外的代码来扩展我们已有 的应用程序.这在很大程度上给我们提供了另外 ...