Skip to content

Commit

Permalink
no-array-for-each: Document another benefit of for-of (#2303)
Browse files Browse the repository at this point in the history
  • Loading branch information
silverwind authored Mar 29, 2024
1 parent 231529a commit 30ece36
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions docs/rules/no-array-for-each.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Benefits of [`for…of` statement](https://developer.mozilla.org/en-US/docs/Web/
- Faster
- Better readability
- Ability to exit early with `break` or `return`
- Ability to skip iterations with `continue`

Additionally, using `for…of` has great benefits if you are using TypeScript, because it does not cause a function boundary to be crossed. This means that type-narrowing earlier on in the current scope will work properly while inside of the loop (without having to re-type-narrow). Furthermore, any mutated variables inside of the loop will picked up on for the purposes of determining if a variable is being used.

Expand Down

0 comments on commit 30ece36

Please sign in to comment.