Archive

Archive for February, 2013

Reserved keywords in JavaScript

February 21, 2013 Leave a comment

List of all reserved words in JavaScript

ECMAScript 1

Source : EcmaSciprt 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 intbytechargotolongfinalfloatshortdoublenative,publicstaticthrowsbooleanpackageprivateabstractvolatileinterfaceprotected,transientimplementsinstanceof, 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 intbytechargotolongfinalfloatshortdoublenative,throwsbooleanabstractvolatiletransient, 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 implementsletprivatepublicinterfacepackageprotectedstatic, 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 sureact like them — they’re disallowed in strict mode too.

Also, the (unlisted) NaNInfinity, 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.

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 

 

Advertisements
Categories: Javascript Tags: