var is a keyword in javascript, but js keywords are not only var, but also break, else, new, case, finally, return, void, catch, for, switch, while, continue, this, with , if, etc.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
javascript keyword
The keyword is a set of names (or commands) used internally in the JavaScript language specified by ECMA-262. These names have specific purposes and users cannot customize identifiers with the same name. Specific instructions are shown in the table.
break | delete | if | this | while |
case | do | in | throw | with |
catch | else | instanceof | try | |
continue | finally | new | typeof | |
debugger(ECMAScript 5 new) | for | return | var | |
default | function | switch | void |
It can be seen that var is a keyword in javascript, but the keywords in js are not only var, but also break and delete , if, this, while, etc.
javascript reserved words
ECMA also describes another set of reserved words that cannot be used as identifiers. Although reserved words do not yet have any specific use in the language, it is possible that they may be used as keywords in the future. The following are all reserved words defined by ECMA version 3:
abstract, enum, int, short, boolean, export, interface, static, byte, extends, long, super, char, final, native, synchronized, class, float, package, throws, const, goto, private, transient, debugger, implements, protected, volatile, double, import, public.
Using keywords as identifiers in code will cause an "Identifier Expected" (missing identifier) error in most browsers. Using reserved words may not cause the same error, depending on the browser. In general, it is best not to use keywords and reserved words as identifiers to maintain compatibility with future versions of ECMAScript.
The content of keywords is not static. As the JavaScript version improves, keywords will also change. For example, ES2015 adds let and const as keywords.
[Recommended learning:javascript advanced tutorial]
The above is the detailed content of Is the javascript keyword var?. For more information, please follow other related articles on the PHP Chinese website!