Reserved Words in JavaScript

I ran into an issue this week while running some old code, where I was using a reserved word in JavaScript, or more accurately a reserved word in a specific browser. Almost two years ago, I thought I was rather smart using self as the variable name to store the Function scope for the Module Pattern, however, several browsers use this internally and can cause surprising conflicts. Later I learned from Douglas Crockford that I should be using that as my keyword, because it is yet to be reserved by the EMCAScript standard, any browsers, or server-side JavaScript technologies. However, it did take me a while to realize my mistake, and I felt it about time to revisit the reserved word list. This post is the amalgamation of what I have learned.

First there are the words that are strictly reserved by the current EMCAScript specification. The following are reserved words and may not be used as variables, functions, methods, or object identifiers:


* These links are provided by the Mozilla Developer Center.

Once we taken care of the existing keywords, we want our code to be forward thinking, so we must look out for planned reserved words as well. The following are reserved as possible future keywords by the ECMAScript specification:


* These links are from About.com.

Next we consider JavaScript 2.0 and additional keywords that are in that specification. The following is a list of keywords for JavaScript 2.0 that have not been previously mentioned:

  • as
  • const
  • export
  • import
  • is
  • use

Mozilla has already reserved the following three JavaScript 2.0 words:


* These links are provided by the Mozilla Developer Center.

Next is the large list of predefined Classes and Objects found in all or most browsers:


* These links are from About.com.

And if that wasnt enough, the following is a large and growing list of global properties and methods:

Global Properties

Global Method


* These links are from About.com.

The Window Object

The Window Object is the global namespace and can be referenced directly within any scope. Also, any variable that is not scoped with the var keyword will be attached to the Window Object.
Properties

* These links are from About.com.

Methods


* These links are from About.com.

Events


* These links are from About.com.

And if all that wasnt enough to worry about, the following are collection of keywords that are reserved by or used by certain browsers:

  • all
  • assign
  • clientInformation
  • element
  • embed
  • embeds
  • event
  • frameRate
  • getClass
  • java
  • JavaArray
  • JavaClass
  • JavaObject
  • JavaPackage
  • layer
  • layers
  • netscape
  • offscreenBuffering
  • opener
  • packages
  • secure
  • status
  • sun
  • taint
  • toSource
  • toString
  • untaint
  • valueOf

Although this is probably not everything, this is the most complete list I have seen of reserved words for JavaScript. I have collected these words here, so each of you can reference it when creating future projects and try to avoid using these words when writing JavaScript.