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.
const
is relatively new for JavaScript. I agree with zerkms. – Joshua Commented Jun 13, 2016 at 22:18