gpt4 book ai didi

javascript - const 在 Edge 15 开发者工具中不起作用

转载 作者:数据小太阳 更新时间:2023-10-29 05:28:39 24 4
gpt4 key购买 nike

我正在运行 Edge/15.15063。 'Can I Use' says const should work.

运行:

const x = 'woo'

然后:

console.log(x)

返回

'x' is undefined

截图:

enter image description here

为什么 const 不起作用?

最佳答案

我怀疑 Edge 控制台在其幕后使用了 with 语句 like other implementations did .这将解释 vareven function declarations被提升到全局范围之外,但是 letconst 将被锁定到 block 范围内:

with (…) {
const x = 'woo'
}
// next input:
with (…) {
console.log(x) // obviously undeclared
}

尝试在单次评估中以多行模式输入它们 - 它们应该可以正常工作。

但您可能还想提交一个错误,因为控制台确实希望感觉像在全局范围内评估事物。

关于javascript - const 在 Edge 15 开发者工具中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44286729/

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