DEV Community

Discussion on: Let's loop - for...in vs for...of

Collapse
 
drewtownchi profile image
Drew Town

I realize this is not a post about whether you should use for loops or not...

I use the AirBNB linting config and they actually error when using either for...in or for...of. I think it is an interesting choice but, it can help avoid the confusion with the various for methods and the subtle changes in functionality.

It is something I have struggled with in some of my code but it seems they prefer you to use Array methods such as ForEach, map, filter. I think the biggest advantage of avoid the for loops is that it helps you reduce side-effect producing code.

The other disadvantage of for..of if you are transpiling is that it requires regenerator-runtime polyfill.

I can't say I've really missed using them in the end even if it was a bit of an adjustment.

Collapse
 
laurieontech profile image
Laurie

All nice points. I don't know that I'm in favor of them or not. I was using them in the example in my tweet because I wanted to really break down what was happening with Object.entries. In production code I don't recall the last time I used them. But either way it was a fun deep dive into the decisions the language makes!