I have a question: What does `for element of arr` buy me over `arr.forEach(element => ...)` I don't find the for...of syntax particularly appealing or useful, but I might be missing something. Is it a matter of preference?
for...of isn't only for arrays. Anything that implements the Symbol.iterator functionality can use for..of, which is pretty nifty for some custom classes and also includes things like the new Map and Set collections, see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... However, even in just arrays there is arguably a benefit. Namely, an extra function being created and invoked with forEach. While in a…
[1] https://developer.mozilla.org/en/docs/Web/JavaScript/Referen...