Last active
May 26, 2017 07:56
-
-
Save dailc/2ea10c47406c581e0420778eba68500a to your computer and use it in GitHub Desktop.
[JS关键字和保留字] JS的关键字和保留字,不能用作标识符 tags:keyword,关键字,保留字
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## ECMA-262 描述了一组具有特定用途的关键字。 | |
这些关键字可用于表示控制语句的开始或结束,或者用于执行特定操作等。 | |
按照规则: | |
关键字是语言保留的,不能用作标识符 | |
| :------------- |:-------------:|:-----:|-----:| | |
| break | do | instanceof | typeof | | |
| case | else | new | var | | |
| catch | finally | return | void | | |
| continue | for | switch | while | | |
| debugger* | function | this | with | | |
| default | if | throw | delete | | |
| in | try | | |
## ECMA-262 还描述了另外一组不能用作标识符的保留字 | |
保留字是指将来可能被作为关键字的存在 | |
| :------------- |:-------------:|:-----:|-----:| | |
| abstract | enum | int | short | | |
| boolean | export | interface | static | | |
| byte | extends | long | super | | |
| char | final | native | synchronized | | |
| class | float | package | throws | | |
| const | goto | private | transient | | |
| debugger | implements | protected | volatile | | |
| double | import | public | | |
## 第五版 | |
第五版在非严格模式下运行的保留字缩减为: | |
| :------------- |:-------------:|:-----:|-----:| | |
| class | enum | extends | super | | |
| const | export | import | | |
在严格模式下额外增加了以下保留字的限制: | |
| :------------- |:-------------:|:-----:|-----:| | |
| implements | package | public | interface | | |
| private | static | let | protected | | |
| yield | | |
注意: 其中`yield`和`let`是第五版新增的保留字,其它都是第三版定义的。 | |
所以为了最大程度兼容,请在第三版的基础上加上这两个字,作为全部保留字和关键字,不允许作为标识符。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment