JavaScript Reserved Keywords
In JavaScript, some identifiers are reserved keywords and cannot be used as variable names or function names.
JavaScript Standard
EcMAScript 3 is fully supported by all modern browsers (ES3, the third edition of JavaScript, starting in 1999).
ECMAScript 4 (ES4) failed.
ECMAScript 5 (ES5, released in 2009) is the latest official version of JavaScript.
OVER TIME, WE'RE STARTING TO SEE THAT ALL MODERN BROWSERS HAVE FULLY SUPPORTED ES5.
JavaScript Preserves Keywords
Reserved keywords in Javascript cannot be used as variables, labels, or function names. Some reserved keywords are used as javascript extensions later.
abstract | arguments | boolean | break | byte |
case | catch | char | class* | const |
continue | debugger | default | delete | of the |
double | else | enum* | eval | export* |
extends* | false | final | finally | float |
for | function | goto | if | implements |
import* | in | instanceof | int | interface |
let | long | native | new | null |
package | private | protected | public | return |
short | static | super* | switch | synchronized |
this | throw | throws | transient | true |
try | typeof | where | void | volatile |
while | with | yield |
* The keyword marked is newly added in ECMAScript5.
JavaScript Objects, Properties, and Methods
You should also avoid using the names of objects, properties, and methods built into JavaScript as variable or function names for JavaScript:
Array | Date | eval | function | hasOwnProperty |
Infinity | isFinite | isNaN | isPrototypeOf | length |
Math | In | name | Number | Object |
prototype | String | toString | undefined | valueOf |
Java Reserved Keywords
JavaScript is often used with Java. You should avoid using some Java objects and properties as JavaScript identifiers:
getClass | java | JavaArray | javaClass | JavaObject | JavaPackage |
Windows Reserves Keywords
JavaScript can be used outside of HTML. It can be used as a programming language in many other applications.
In HTML, you must (and for portability reasons as well) avoid using HTML and Windows object and property names as variable and function names in JavaScript:
alert | all | anchor | anchors | area |
assign | blur | button | checkbox | clearInterval |
clearTimeout | clientInformation | close | closed | confirm |
constructor | crypto | decodeURI | decodeURIComponent | defaultStatus |
document | element | elements | embed | embeds |
encodeURI | encodeURIComponent | escape | event | fileUpload |
focus | form | forms | frame | innerHeight |
innerWidth | layer | layers | link | location |
mimeTypes | navigate | navigator | frames | frameRate |
hidden | history | image | images | offscreenBuffering |
open | opener | option | outerHeight | outerWidth |
packages | pageXOffset | pageYOffset | parent | parseFloat |
parseInt | password | pkcs11 | plugin | prompt |
propertyIsEnum | radio | reset | screenX | screenY |
scroll | secure | select | self | setInterval |
setTimeout | status | submit | taint | text |
textarea | top | unescape | untaint | window |
HTML Event Handler
In addition, you should also avoid using the name of the HTML event handler as the name of the Javascript variable and function.
Examples:
onblur | onclick | onerror | onfocus |
onkeydown | onkeypress | onkeyup | onmouseover |
onload | onmouseup | onmousedown | onsubmit |
Non-standard JavaScript
In addition to reserved keywords, there are also some non-standard keywords in the JavaScript implementation.
An example is the const keyword, which is used to define variables. Some JavaScript engines treat const as a synonym for var. Other engines treat const as the definition of read-only variables.
Const is an extension of JavaScript. The JavaScript engine supports it for use in Firefox and Chrome. But it is not part of the JavaScript standard ES3 or ES5.
Recommendation: Don't use it.