In JavaScript, some identifiers are reserved words and cannot be used as variables or function names.
JavaScript Reserved Words
In JavaScript you cannot use these reserved words as variables, labels, or function names:
| 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 |
JavaScript Objects, Properties, and Methods
You should also avoid using the name of JavaScript objects, properties, and methods:
| Array | Date | eval | function | hasOwnProperty |
| Infinity | isFinite | isNaN | isPrototypeOf | length |
| Math | NaN | name | Number | Object |
| prototype | String | toString | undefined | valueOf |
Java Reserved Words
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 |
Windows Reserved Words
JavaScript can be used outside HTML. It can be used as the programming language in many other applications.
In HTML you must (for portability you should) avoid using the name of HTML and Windows objects and properties:
| 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 name of HTML event handlers like these:
| onbeforeunload | onblur | ondragdrop | onclick | oncontextmenu |
| ondragdrop | onerror | onfocus | onkeydown | onkeypress |
| onkeyup | onmouseover | onload | onmouseup | onmousedown |
| onreset | onmousemove | onsubmit | onmouseout | onunload |
No comments:
Post a Comment