来源 :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. redis-cluster 单个节点不可用

    背景: 公司的音视频 盗版检测业务,使用redis-cluster作为 key-value 数据库, 使用张图片的 特征hash值作key.因为数据量太大,机器有限,集群内没有slaver 问题描述 ...

  2. Android倒计时:计算两个时间将得到的时间差转化为倒计时(xx时xx分xx秒格式)

    首先是一个自定义控件: public class RushBuyCountDownTimerView extends LinearLayout { // 小时,十位 private TextView ...

  3. 【php学习】PHP 入门经典第二章笔记

    问题答疑: 1.默认情况下,Apache服务器的配置文件名.MySQL服务器的配置文件名以及PHP预处理器配置文件名分别是什么?Apache默认主配置文件:根目录下config文件夹下httpd.co ...

  4. Codeforces Round #379 (Div. 2) A B C D 水 二分 模拟

    A. Anton and Danik time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  5. ASCII电脑编码

    Bin Dec Hex 缩写/字符 解释 0000 0000 0 00 NUL(null) 空字符 0000 0001 1 01 SOH(start of headline) 标题开始 0000 00 ...

  6. CSS中的text-overflow:clip|ellipsis的使用

    如果想让某个容器(div或者li或者...块级元素)显示一行文字,当文字内容过多时,不换行,而是出现...,可以使用text-overflow:clip|ellipsis 基本语法:text-over ...

  7. 通过BroadCast与service时时监听网络变化

    首先需要一个service: 这里我定义了一个NetworkStateService,在这个service中我写了一个BroadcastReceiver用于监听网络状态发生改变的情况并在这个servi ...

  8. SpringMVC中使用Cron表达式的定时器

    SpringMVC中使用Cron表达式的定时器 cron(定时策略)简要说明 顺序: 秒 分 时 日 月 星期 年份 (7个参数,空格隔开各个参数,年份非必须参数) 通配符: , 如果分钟位置为* 1 ...

  9. google 版本号49之后chrome的跨域设置

  10. ubuntu 安装git服务器

    ubuntu14.04安装git,搭建环境 1.sudo apt-get install git 2.生成key ssh-keygen -t rsa 3.保存其他用户,创建的ssh用户密码 cd .s ...