May 06, 2021 JavaScript
1. JavaScript retains keywords
3. JavaScript retains keywords
Keep keywords that are meant to be words that will be retained as future keywords.
In JavaScript, some identifiers are reserved keywords and cannot be used as variable or function names.
All modern browsers fully support ECMAScript 3 (ES3, the third version of JavaScript, since 1999).
ECMAScript 4 (ES4) failed.
ECMAScript 5 (ES5, released in 2009) is the latest official version of JavaScript.
As time goes on, we begin to see that all modern browsers are fully supported by ES5.
Javascript's reserved keywords cannot be used as variables, tags, 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 | 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 |
The tagged keywords are newly added in ECMAScript5.
You should also avoid using the names of objects, properties, and methods built into JavaScript as variables or function names for JavaScript:
Array | Date | Eval | function | hasOwnProperty |
Infinity | isFinite | isNaN | isPrototypeOf | length |
Math | NaN | name | Number | Object |
prototype | String | Tostring | undefined | valueOf |
JavaScript is often used with Java. You should avoid using some Java objects and properties as JavaScript identifiers:
getClass | Java | JavaArray | javaClass | JavaObject | JavaPackage |
JavaScript can be used outside of HTML. It can be used as a programming language in many other applications.
In HTML, you must (and you should do the same for portability) avoid using the names of HTML and Windows objects and properties as variables and function names for 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 |
In addition, you should also avoid using the name of the HTML event handle as a variable and function name of JavaScript.
Example:
onblur | onclick | onerror | onfocus |
onkeydown | onkeypress | onkeyup | onmouseover |
onload | onmouseup | onmousedown | onsubmit |
Notice: In JavaScript, the keyword cannot be used as a variable name or a function name, otherwise an error message may be obtained, such as "Identifier Expected", "" Identifier Expected "(Item, Design Identifier)."
In addition to keep keywords, there are also some non-standard keywords in JavaScript implementation.
One instance is const Keywords are used to define variables.Some JavaScript engines treat const as synonyms of VAR.Other engines use the Const as the definition of a read-only variable.
Const is an extension of JavaScript.The JavaScript engine supports it in Firefox and Chrome.But it is not an integral part of the JavaScript standard ES3 or ES5. Suggestion: Don't use it 。