- 第1节:javascript 简介
- 第2节:JavaScript 用法
- 第3节:JavaScript 输出
- 第4节:JavaScript 语法
- 第5节:JavaScript 语句
- 第6节:JavaScript 注释
- 第7节:JavaScript 变量
- 第8节:JavaScript 数据类型
- 第9节:JavaScript 函数
- 第10节:JavaScript 作用域
- 第11节:JavaScript 事件
- 第12节:JavaScript 字符串
- 第13节:JavaScript 运算符
- 第14节:JavaScript 比较和逻辑运算符
- 第15节:JavaScript 位运算符
- 第16节:JavaScript if…else 语句
- 第17节:JavaScript switch 语句
- 第18节:JavaScript for 循环
- 第19节:JavaScript while 循环
- 第20节:JavaScript Break 和 Continue 语句
- 第21节:JavaScript 类型转换
- 第22节:JavaScript 正则表达式
- 第23节:JavaScript 错误处理(Throw、Try 和 Catch)
- 第24节:JavaScript 调试
- 第25节:JavaScript 表单验证
- 第26节:JavaScript 保留关键字
- 第27节:JavaScript JSON
- 第28节:javascript:void(0) 含义
- 第29节:JavaScript 代码规范
JavaScript 保留关键字
保留关键字在意思上表达成为将来的关键字而保留的单词。
在 JavaScript 中,一些标识符是保留关键字,不能用作变量名或函数名。
JavaScript 标准
所有的现代浏览器完全支持 ECMAScript 3(ES3,JavaScript 的第三版,从 1999 年开始)。
ECMAScript 4(ES4)未通过。
ECMAScript 5(ES5,2009 年发布),是 JavaScript 最新的官方版本。
随着时间的推移,我们开始看到,所有的现代浏览器已经完全支持 ES5。
JavaScript 保留关键字
Javascript 的保留关键字不可以用作变量、标签或者函数名。有些保留关键字是作为 Javascript 以后扩展使用。
* 标记的关键字是 ECMAScript5 中新添加的。
JavaScript 对象、属性和方法
您也应该避免使用 JavaScript 内置的对象、属性和方法的名称作为 Javascript 的变量或函数名:
Java 保留关键字
JavaScript 经常与 Java 一起使用。您应该避免使用一些 Java 对象和属性作为 JavaScript 标识符:
Windows 保留关键字
JavaScript 可以在 HTML 外部使用。它可在许多其他应用程序中作为编程语言使用。
在 HTML 中,您必须(为了可移植性,您也应该这么做)避免使用 HTML 和 Windows 对象和属性的名称作为 Javascript 的变量及函数名:
HTML 事件句柄
除此之外,您还应该避免使用 HTML 事件句柄的名称作为 Javascript 的变量及函数名。
实例:
注意:在JavaScript中关键字不能用作变量名或者函数名,否则可能会得到错误消息,例如“"Identifier Expected"(应该有标识符、期望标识符)”。
非标准 JavaScript
除了保留关键字,在 JavaScript 实现中也有一些非标准的关键字。
一个实例是 const 关键字,用于定义变量。 一些 JavaScript 引擎把 const 当作 var 的同义词。另一些引擎则把 const 当作只读变量的定义。
Const 是 JavaScript 的扩展。JavaScript 引擎支持它用在 Firefox 和 Chrome 中。但是它并不是 JavaScript 标准 ES3 或 ES5 的组成部分。建议:不要使用它。