Crockford's JavaScript: The Good Parts contains the following text.
Crockford的JavaScript:好的部分包含以下文本。
Reserved Words
保留字
The following words are reserved in JavaScript:
以下是JavaScript中保留的单词:
abstract boolean break byte case catch char class const continue debugger default delete do double else enum export extends false final finally float for function goto if implements import in instanceof int interface long native new null package private protected public return short static super switch synchronized this throw throws transient true try typeof var volatile void while with
Most of these words are not used in the language.
这些词大部分都没有在语言中使用。
They cannot be used to name variables or parameters. When reserved words are used as keys in object literals, they must be quoted. They cannot be used with the dot notation, so it is sometimes necessary to use the bracket notation instead:
它们不能用于命名变量或参数。当保留词在对象文字中用作键时,它们必须被引用。它们不能与点表示法一起使用,因此有时需要使用括号表示法来代替:
var method; // ok var class; // illegal object = {box: value}; // ok object = {case: value}; // illegal object = {'case': value}; // ok object.box = value; // ok object.case = value; // illegal object['case'] = value; // ok
Some of the reserved words appear to not be reserved in my installed interpreters. For example, in both Chrome 48 (beta) and node.js 0.10.40 the following code will successfully add two numbers identified by reserved words.
在我安装的解释器中,有些保留的词似乎没有保留。例如,在Chrome 48 (beta)和node。以下代码将成功添加两个由保留字标识的数字。
var abstract = 1;
var native = 1;
abstract + native;
> 2
Why can I use these two reserved words as variable names? Am I missing something crucial?
为什么我可以用这两个保留词作为变量名?我是不是漏掉了什么重要的东西?
2 个解决方案
#1
5
Reserved keywords as of ECMAScript 6
保留关键字如ECMAScript 6
break case class catch const continue debugger default delete do else
export extends finally for function if import in instanceof new return
super switch this throw try typeof var void while with yield
and abstract
and native
(more here) were reserved as future keywords by older ECMAScript specifications (ECMAScript 1 till 3).
抽象的和原生的(这里有更多)被旧的ECMAScript规范保留为未来的关键字(ECMAScript 1到3)。
always reserved : enum
总是保留:枚举
reserved when they are found in strict mode code:
在严格模式码中发现时保留:
implements package protected static let interface private public
reserved when they are found in module code: await
在模块代码中找到它们时保留:wait
#2
0
A reserved word (also known as a reserved identifier or keyword) is a word that cannot be used as an identifier, such as the name of a variable, function, or label – it is "reserved from use". Reserved words or keywords have special meaning within the programming languages. They are use to identify the data types in language that supports the system, which identify the blocks and loops, etc. so their functionality is is already defined in the system library.
保留字(也称为保留标识符或关键字)是不能用作标识符的词,例如变量、函数或标签的名称——它是“保留使用”。保留词或关键字在编程语言中有特殊的意义。它们用于识别支持系统的语言中的数据类型,系统识别块和循环等,因此它们的功能已经在系统库中定义。
Including keywords or reserved words in your code, create confusion to other developers as well as the compiler at the time that you run your code. That is why reserved words is not allow for many programming languages. There are some other programming language that have similar keywords; such as C, C++, C#, and Java they share a commonality.
在您的代码中包含关键字或保留的单词,会给其他开发人员以及运行代码时的编译器造成混乱。这就是为什么许多编程语言不允许使用保留字。还有一些编程语言具有类似的关键字;例如C、c++、c#和Java,它们有一个共同之处。
Here you can get the most updated list of Reserved Words in JavaScript, it also contains useful examples.
在这里,您可以获得最新的JavaScript保留词列表,它还包含一些有用的示例。
#1
5
Reserved keywords as of ECMAScript 6
保留关键字如ECMAScript 6
break case class catch const continue debugger default delete do else
export extends finally for function if import in instanceof new return
super switch this throw try typeof var void while with yield
and abstract
and native
(more here) were reserved as future keywords by older ECMAScript specifications (ECMAScript 1 till 3).
抽象的和原生的(这里有更多)被旧的ECMAScript规范保留为未来的关键字(ECMAScript 1到3)。
always reserved : enum
总是保留:枚举
reserved when they are found in strict mode code:
在严格模式码中发现时保留:
implements package protected static let interface private public
reserved when they are found in module code: await
在模块代码中找到它们时保留:wait
#2
0
A reserved word (also known as a reserved identifier or keyword) is a word that cannot be used as an identifier, such as the name of a variable, function, or label – it is "reserved from use". Reserved words or keywords have special meaning within the programming languages. They are use to identify the data types in language that supports the system, which identify the blocks and loops, etc. so their functionality is is already defined in the system library.
保留字(也称为保留标识符或关键字)是不能用作标识符的词,例如变量、函数或标签的名称——它是“保留使用”。保留词或关键字在编程语言中有特殊的意义。它们用于识别支持系统的语言中的数据类型,系统识别块和循环等,因此它们的功能已经在系统库中定义。
Including keywords or reserved words in your code, create confusion to other developers as well as the compiler at the time that you run your code. That is why reserved words is not allow for many programming languages. There are some other programming language that have similar keywords; such as C, C++, C#, and Java they share a commonality.
在您的代码中包含关键字或保留的单词,会给其他开发人员以及运行代码时的编译器造成混乱。这就是为什么许多编程语言不允许使用保留字。还有一些编程语言具有类似的关键字;例如C、c++、c#和Java,它们有一个共同之处。
Here you can get the most updated list of Reserved Words in JavaScript, it also contains useful examples.
在这里,您可以获得最新的JavaScript保留词列表,它还包含一些有用的示例。