From c198fdc64e6e84e975c3cd95adfcddc67d1a3ea8 Mon Sep 17 00:00:00 2001 From: Bryan Mishkin <698306+bmish@users.noreply.github.com> Date: Wed, 24 Mar 2021 16:11:10 -0400 Subject: [PATCH] docs: elaborate on benefits/restrictions of for-of loops in `no-array-for-each` rule doc --- docs/rules/no-array-for-each.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/rules/no-array-for-each.md b/docs/rules/no-array-for-each.md index c0dd2986d2..23926fe4df 100644 --- a/docs/rules/no-array-for-each.md +++ b/docs/rules/no-array-for-each.md @@ -1,9 +1,15 @@ # Prefer `for…of` over `Array#forEach(…)` -A [`for…of` statement](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of) is more readable than [`Array#forEach(…)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach). +Benefits of [`for…of` statement](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of) over [`Array#forEach(…)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach) can include: + +* Better readability +* No additional scope, can mean easier debugging +* Ability to early exit with `break` / `return` This rule is partly fixable. +Note that this rule may erroneously catch/fix loops with arrays that are not iterable and thus cannot be converted to for-of loops. + ## Fail ```js