JavaScript Reserved Keywords
In JavaScript, some identifiers are reserved keywords and cannot be used as variable names or function names.
JavaScript standards
All modern browsers fully support ECMAScript 3 (ES3, the third edition of JavaScript, from 1999).
ECMAScript 4 (ES4) was not adopted.
ECMAScript 5 (ES5, released in 2009).
ECMAScript 6 (ES6, released in 2015) is the latest official version of JavaScript.
Over time, we have seen that all modern browsers fully support ES6.
JavaScript Reserved Keywords
JavaScript reserved keywords cannot be used as variables, labels, or function names. Some reserved keywords are reserved for future extensions of JavaScript.
| abstract | arguments | boolean | break | byte |
|---|---|---|---|---|
| case | catch | char | class* | const |
| continue | debugger | default | delete | do |
| 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 | var | void | volatile |
| while | with | yield |
- Marked keywords were newly added in ECMAScript 5.
JavaScript objects, properties, and methods
You should also avoid using the names of JavaScript built-in objects, properties, and methods as JavaScript variable or function names:
| Array | Date | eval | function | hasOwnProperty |
|---|---|---|---|---|
| Infinity | isFinite | isNaN | isPrototypeOf | length |
| Math | NaN | name | Number | Object |
| prototype | String | toString | undefined | valueOf |
Java reserved keywords
JavaScript is often used together with Java. You should avoid using some Java objects and properties as JavaScript identifiers:
| getClass | java | JavaArray | javaClass | JavaObject | JavaPackage |
|---|
Window reserved 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 you should) avoid using the names of HTML and Window objects and properties as JavaScript variable and function names:
| 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 handlers
In addition, you should avoid using the names of HTML event handlers as JavaScript variable and function names.
Example:
| onblur | onclick | onerror | onfocus |
|---|---|---|---|
| onkeydown | onkeypress | onkeyup | onmouseover |
| onload | onmouseup | onmousedown | onsubmit |