Const must be initialized error in Microsoft Edge in for...of loop
Const must be initialized error in Microsoft Edge in for...of loop
我正在使用 const
和 JavaScript 的新 for of
循环结构。它在 Chrome 中运行良好,但在 MS Edge 中,以下代码会引发错误:
for(const a of [1, 2, 3])
console.log(a);
Error: Const must be initialized
同样,在 chrome 中工作正常,边缘抛出错误。我猜它期望 const 变量有一个初始化值,但这就是 for 的全部工作,不是吗?
MDN 表示 edge 支持循环,因此浏览器支持不是问题。
根据 https://kangax.github.io/compat-table/es6,“const
in for-of
loop iteration scope”在 IE 和 Edge 中不受支持,直到版本14. 顺便说一句,let
也是一样的。基本 for of
循环和基本 const
/let
用法确实有效。 MDN 不是浏览器支持的最准确来源。
我正在使用 const
和 JavaScript 的新 for of
循环结构。它在 Chrome 中运行良好,但在 MS Edge 中,以下代码会引发错误:
for(const a of [1, 2, 3])
console.log(a);
Error: Const must be initialized
同样,在 chrome 中工作正常,边缘抛出错误。我猜它期望 const 变量有一个初始化值,但这就是 for 的全部工作,不是吗?
MDN 表示 edge 支持循环,因此浏览器支持不是问题。
根据 https://kangax.github.io/compat-table/es6,“const
in for-of
loop iteration scope”在 IE 和 Edge 中不受支持,直到版本14. 顺便说一句,let
也是一样的。基本 for of
循环和基本 const
/let
用法确实有效。 MDN 不是浏览器支持的最准确来源。