Is the javascript keyword var?

青灯夜游
Release: 2023-01-07 11:47:32
Original
1864 people have browsed it

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.

Is the javascript keyword var?

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.

ECMAScript Keywords
breakdelete ifthis while
casedointhrowwith
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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!