loading...

[REMINDER-4] For-of loop

f3ltron profile image florent giraud ・1 min read

For-of loop

The nice to know about this is that for-of get the conscience of forEach. And give you the possibility to break it.

for (const v of ['a', 'b', 'c']) {
  console.log(v);
}

Look at the const here. As the for of will create a new scope (Go to REMINDER 1 if you want to know more about scope).
Effectively it will be transpiled by

for (var _i = 0, _a = ["a", "b", "c"]; _i < _a.length; _i++) {
    var v = _a[_i];
    console.log(v);
}

With transpilation v will not be accessible even if real life here v will the last value of the array "c"

Discussion

pic
Editor guide