ECMA-262 描述了一組具有特定用途的關鍵字。這些關鍵字可用於表示控制語句的開始或結束,或者用於執行特定操作等。按照規則,關鍵字也是語言保留的,不能用作標識符。以下就是ECMAScript的全部關鍵字(帶*號上標的是第5 版新增的關鍵字):
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 還描述了另外一組不能用作標識符的保留字。盡管保留字在這門語言中還沒有任何特定的用途。但它們有可能在將來被用作關鍵字。以下是ECMA-262 第3 版定義的全部保留字:
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 |
第5 版把在非嚴格模式下運行時的保留字縮減為下列這些:
class | enum | extends | super |
const | export | import |
在嚴格模式下,第5 版還對以下保留字施加了限制:
implements | package | public | interface |
private | static | let | protected |
yield |
注意, let 和yield 是第5 版新增的保留字;其他保留字都是第3 版定義的。為了最大程度地保證兼容性,建議大家將第3 版定義的保留字外加let 和yield 作為編程時的參考。