





























Looking for a list of all reserved words in JavaScript? You’ve come to the right place. I recently needed such a list myself, but ended up comparing the reserved keywords in all ECMAScript versions as well. The result is listed below, for future reference.
In the beginning, there was ECMAScript 1. It listed the following reserved words:
do
if
in
for
new
try
var
case
else
enum
null
this
true
void
with
break
catch
class
const
false
super
throw
while
delete
export
import
return
switch
typeof
default
extends
finally
continue
debugger
function
Later, ECMAScript 2 added int, byte, char, goto, long, final, float, short, double, native, public, static, throws, boolean, package, private, abstract, volatile, interface, protected, transient, implements, instanceof, and synchronized.
do
if
in
for
int
new
try
var
byte
case
char
else
enum
goto
long
null
this
true
void
with
break
catch
class
const
false
final
float
short
super
throw
while
delete
double
export
import
native
public
return
static
switch
throws
typeof
boolean
default
extends
finally
package
private
abstract
continue
debugger
function
volatile
interface
protected
transient
implements
instanceof
synchronized
ECMAScript 3 introduced no changes in the list of reserved keywords — it’s identical to the ECMAScript 2 keywords.
There is no such thing as ECMAScript 4.
ECMASCript 5/5.1 removed int, byte, char, goto, long, final, float, short, double, native, throws, boolean, abstract, volatile, transient, and synchronized; it added let, and yield.
do
if
in
for
let
new
try
var
case
else
enum
eval
null
this
true
void
with
break
catch
class
const
false
super
throw
while
yield
delete
export
import
public
return
static
switch
typeof
default
extends
finally
package
private
continue
debugger
function
arguments
interface
protected
implements
instanceof
Note that implements, let, private, public, interface, package, protected, static, and yield are disallowed in strict mode only.
You may have noticed I included eval and arguments in the list. These are not strictly reserved words, but they sure act like them — they’re disallowed in strict mode too.
Also, the (unlisted) NaN, Infinity, and undefined properties of the global object are immutable or read-only properties in ES5. So even though var NaN = 42; in the global scope wouldn’t throw an error, it wouldn’t actually do anything. To avoid confusion, I’d suggest avoiding the use of these identifiers altogether, even though they’re not strictly reserved words.
The latest ECMAScript 2015 (ES6) draft adds await as a future reserved word within modules. let and yield are now disallowed even in non-strict mode code. In some contexts yield is given the semantics of an identifier.
do
if
in
for
let
new
try
var
case
else
enum
eval
null
this
true
void
with
await
break
catch
class
const
false
super
throw
while
yield
delete
export
import
public
return
static
switch
typeof
default
extends
finally
package
private
continue
debugger
function
arguments
interface
protected
implements
instanceof
Reserved keywords may not be used as variable names in JavaScript. For optimal backwards compatibility with older JavaScript engines, it’s best to avoid using the keywords on this page as variable names or property names — even the old ECMAScript 2 ones like char and default.
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。