A keyword is a word that has special significance in the JavaScript language. It follows the rules that ECMA lays down for describing identifiers. All of the JavaScript keywords are reserved and define the language syntax. You must not use any of them as identifier names for variables, properties, methods and functions that you define.
ECMAScript reserves a set of keywords for future use. These are intended to make provision for future language features and to give developers warning that they should avoid using these keywords in order that their scripts should continue to operate when the language is revised.
Other special names are defined by JavaScript to identify properties of the Global object and constructor functions of the built-in data types. You should avoid these too, unless you are intentionally overriding their functionality with your own.
Here is a list of keywords that ECMA edition 2 mandates a compliant implementation should support:
break
continue
delete
else
for
function
if
in
new
return
this
typeof
var
void
while
with
In addition, these are constants that should also be avoided:
true
false
null
The third edition of the ECMA standard adds these keywords which in the earlier edition were reserved for future use:
case
catch
default
do
finally
instanceof
switch
throw
try
The remaining reserved keywords as of edition 3 are:
abstract
boolean
byte
char
class
const
debugger
double
enum
export
extends
final
float
goto
implements
import
int
interface
long
native
package
private
protected
public
short
static
super
synchronized
throws
transient
volatile
However, you should note that Netscape anticipates a future standard and supports these already:
export
import
The JavaScript 2.0 project defines these which should also be avoided and which will likely be added to a later edition of the ECMAScript standard:
namespace
use
Many implementations of JavaScript will introduce additional keywords. Some will provide functional behavior for the reserved keywords. To remain ECMAScript compliant, the reserved words specified in edition 3 must be supported sufficiently to prevent parsing errors, but need not provide any meaningful functionality.
You can code defensively to avoid any future problems. Using an underscore character or digit in your identifier names should improve the chances of your script continuing to operate properly in later versions of the language. Using upper case may help, but is less of a guarantee of safety. In particular, you should be very careful to avoid the names of properties and methods belonging to the Global object.
See also: | Lexical element, Reserved word, Token |
Prev | Home | Next |
Keyboard events | Up | L |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |