gpt4 book ai didi

javascript - 在 javascript ECMAScript6 中声明变量 "let"

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:31:55 24 4
gpt4 key购买 nike

为什么我不能声明 const 或 var,却可以声明名为 let 的变量。我知道我永远不会那样做,但我只是好奇是否有合理的解释。所以我可以这样做:

var let = 5;
let x = 3;
x + let -> 8

为什么这是可能的?

最佳答案

来自Mozilla Developer Network siteFuture reserved keywords 下:

The following are only reserved when they are found in strict mode code:

其中包括 let

但是,constvar 列在 Reserved keywords as of ECMAScript 6this document 下显示它们最初在 ECMAScript 1 中保留的历史。

Strict Mode

To invoke strict mode for an entire script, put the exact statement "use strict"; (or 'use strict';) before any other statements.

什么是严格模式?

ECMAScript 5's strict mode is a way to opt in to a restricted variant of JavaScript. Strict mode isn't just a subset: it intentionally has different semantics from normal code. Browsers not supporting strict mode will run strict mode code with different behavior from browsers that do

关于javascript - 在 javascript ECMAScript6 中声明变量 "let",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37877901/

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