gpt4 book ai didi

javascript - 一些 JavaScript 保留字用作变量

转载 作者:可可西里 更新时间:2023-11-01 02:44:35 25 4
gpt4 key购买 nike

Crockford 的 JavaScript: The Good Parts 包含 the following text .

Reserved Words

The following words are reserved in 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

有些保留字在我安装的解释器中似乎没有保留。例如,在 Chrome 48(测试版)和 node.js 0.10.40 中,以下代码将成功添加两个由保留字标识的数字。

var abstract = 1;
var native = 1;
abstract + native;
> 2

为什么我可以用这两个保留字作为变量名呢?我是否遗漏了一些重要的东西?

最佳答案

Reserved keywords as of 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 abstractnative ( more here ) 被旧的 ECMAScript 规范(ECMAScript 1 到 3)保留为 future 的关键字。

始终保留:enum

在严格模式代码中发现时保留:

implements package  protected  static  let  interface  private  public

在模块代码中找到它们时保留:await

关于javascript - 一些 JavaScript 保留字用作变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34559947/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com