Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Const must be initialized error in Microsoft Edge in for...of loop

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.

like image 596
Achshar Avatar asked Jun 13 '16 21:06

Achshar


1 Answers

According 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.

like image 101
Bergi Avatar answered Oct 24 '22 05:10

Bergi