我正在运行 Edge/15.15063。 'Can I Use' says const should work.
运行:
const x = 'woo'
然后:
console.log(x)
返回
'x' is undefined
截图:
为什么 const 不起作用?
最佳答案
我怀疑 Edge 控制台在其幕后使用了 with
语句 like other implementations did .这将解释 var
和 even function
declarations被提升到全局范围之外,但是 let
和 const
将被锁定到 block 范围内:
with (…) {
const x = 'woo'
}
// next input:
with (…) {
console.log(x) // obviously undeclared
}
尝试在单次评估中以多行模式输入它们 - 它们应该可以正常工作。
但您可能还想提交一个错误,因为控制台确实希望感觉像在全局范围内评估事物。
关于javascript - const 在 Edge 15 开发者工具中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44286729/