Skip to content

Commit 80efcda

Browse files
authored
Merge pull request #2180 from vsemozhetbyt/patch-6
Add a note on some()/every() short circuit
2 parents 37f67e6 + dea1a2d commit 80efcda

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

1-js/05-data-types/05-array-methods/article.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,8 @@ These methods are the most used ones, they cover 99% of use cases. But there are
741741
- [arr.some(fn)](mdn:js/Array/some)/[arr.every(fn)](mdn:js/Array/every) checks the array.
742742

743743
The function `fn` is called on each element of the array similar to `map`. If any/all results are `true`, returns `true`, otherwise `false`.
744+
745+
These methods behave sort of like `||` and `&&` operators: if `fn` returns a truthy value, `arr.some()` immediately returns `true` and stops iterating over the rest items; if `fn` returns a falsy value, `arr.every()` immediately returns `false` and stops iterating over the rest items as well.
744746

745747
We can use `every` to compare arrays:
746748
```js run

0 commit comments

Comments
 (0)