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.
ECMAScript 1
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
ECMAScript 2
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
ECMAScript 3 introduced no changes in the list of reserved keywords — it’s identical to the ECMAScript 2 keywords.
ECMAScript 4
There is no such thing as ECMAScript 4.
ECMAScript 5
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.
ECMAScript 2015 (ES6)
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
What’s the use?
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
.
Comments
Timmy Willison wrote on :
Thanks for putting this together Mathias!
Bastian Behrens wrote on :
Thanks for the lists. Would be great if you could order them alphabetically and put the lists up to GitHub.
Mathias wrote on :
Bastian: I ordered them by length (and then alphabetically) because that’s the order I need them in most of the time. See e.g. the source code for my variable name validator tool, or Esprima’s source code.
I figured it’s easy enough to sort the lists alphabetically if that’s what you need — most editors even have built-in macros for that.
Bastian Behrens wrote on :
Of course it’s easy :) Now that you mention it, I see that you ordered them by length ;-) Did not know about your name validator tool — thanks for that!
Michael Lange wrote on :
RickRolled :(
Neat history though. It’s strange seeing all those OOPish and static concepts reserved in ES2–“Java-erScript”.
Martin Rinehart wrote on :
A little bit of history, a little bit of scholarship, a Very Good Thing! Thanks.
Since you mention it: http://www.martinrinehart.com/frontend-engineering/engineers/html/html-tag-history.html
maxw3st wrote on :
Thanks for the list Mathias. This’ll be handy as I continue learning the language.
Kenneth Auchenberg wrote on :
Great overview Mathias! What about sorting the list alphabetically, for better overview?
Mathias wrote on :
Kenneth: See comment #3.
Edward wrote on :
I don’t quite get why
boolean
isn’t used in JavaScript but the!!
operator is used to convert to a boolean.But not
Mathias wrote on :
Edward: You could use
Boolean
for that if you want: