Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'm all about making sure that code is optimized for humans first and computers second.

Here is the specific remark I was referring to: Or even better, just use .forEach which doesn't have the same caveats as declaring functions in for loops.

Blindly applying forEach is simply not the right answer here.



I'd suggest the opposite: forEach() is smaller that iterating over indexes and creates a scope by default which (although having overhead) will prevent a lot of common last-case-wins scenarios that frequently trap both new and experienced developers.

Should we use a .forEach() for a 1 million item array? No. Performance would be a problem. For the typical use case of items like the demo [1, 2, 3]? Yes, this would be be simpler.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: