Mathias Bynens

Reserved keywords in JavaScript

· 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 6

At the time of writing, the latest ECMAScript 6 draft still lists the same reserved keywords as in ECMAScript 5/5.1. However, let is now disallowed even in non-strict mode code. Supposedly the same thing goes for yield.

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

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

Leave a comment

Comment on “Reserved keywords in JavaScript”

Some Markdown is allowed; HTML isn’t. Keyboard shortcuts are available.

It’s possible to add emphasis to text:

_Emphasize_ some terms. Perhaps you’d rather use **strong emphasis** instead?

Select some text and press + I on Mac or Ctrl + I on Windows to make it italic. For bold text, use + B or Ctrl + B.

To create links:

Here’s an inline link to [Google](http://www.google.com/).

If the link itself is not descriptive enough to tell users where they’re going, you might want to create a link with a title attribute, which will show up on hover:

Here’s a [poorly-named link](http://www.google.com/ "Google").

Use backticks (`) to create an inline <code> span:

In HTML, the `p` element represents a paragraph.

Select some inline text and press + K on Mac or Ctrl + K on Windows to make it a <code> span.

Indent four spaces to create an escaped <pre><code> block:

    printf("goodbye world!"); /* his suicide note
was in C */

Alternatively, you could use triple backtick syntax:

```
printf("goodbye world!"); /* his suicide note
was in C */
```

Select a block of text (more than one line) and press + K on Mac or Ctrl + K on Windows to make it a preformatted <code> block.

Quoting text can be done as follows:

> Lorem iPad dolor sit amet, consectetur Apple adipisicing elit,
> sed do eiusmod incididunt ut labore et dolore magna aliqua Shenzhen.
> Ut enim ad minim veniam, quis nostrud no multi-tasking ullamco laboris
> nisi ut aliquip iPad ex ea commodo consequat.

Select a block of text and press + E on Mac or Ctrl + E on Windows to make it a <blockquote>.