Mathias Bynens

Reserved keywords in JavaScript

Published · tagged with JavaScript

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.

About me

Hi there! I’m Mathias. I work on Chrome DevTools and the V8 JavaScript engine at Google. HTML, CSS, JavaScript, Unicode, performance, and security get me excited. Follow me on Twitter, Mastodon, and GitHub.

Comments

Bastian Behrens wrote on :

Thanks for the lists. Would be great if you could order them alphabetically and put the lists up to GitHub.

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”.

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.

var a = !!'bool'; // true

But not

var a = boolean('bool'); // error

Leave a comment

Comment on “Reserved keywords in JavaScript”

Your input will be parsed as Markdown.