admin管理员组文章数量:1225076
I am using const
with the new for of
looping structure of JavaScript. It works fine in Chrome but in MS Edge the following code throws error:
for(const a of [1, 2, 3])
console.log(a);
Error: Const must be initialized
Again, works fine in chrome, edge throws error. I guess it expects const variable to have an initialization value but that's the entire job of the for isn't it?
MDN says edge supports the loop so browser support isn't an issue.
I am using const
with the new for of
looping structure of JavaScript. It works fine in Chrome but in MS Edge the following code throws error:
for(const a of [1, 2, 3])
console.log(a);
Error: Const must be initialized
Again, works fine in chrome, edge throws error. I guess it expects const variable to have an initialization value but that's the entire job of the for isn't it?
MDN says edge supports the loop so browser support isn't an issue.
Share Improve this question asked Jun 13, 2016 at 21:47 AchsharAchshar 5,2438 gold badges42 silver badges72 bronze badges 3 |1 Answer
Reset to default 18According to https://kangax.github.io/compat-table/es6, "const
in for-of
loop iteration scope" is not supported in IE and not in Edge until version 14. It's the same with let
btw. Basic for of
loops, and basic const
/let
usage do work though. MDN is not the most accurate source for browser support.
本文标签: javascriptConst must be initialized error in Microsoft Edge in forof loopStack Overflow
版权声明:本文标题:javascript - Const must be initialized error in Microsoft Edge in for...of loop - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739393889a2161295.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
const
is relatively new for JavaScript. I agree with zerkms. – Joshua Commented Jun 13, 2016 at 22:18