Example 1 — Check If All Numbers Are Even
Return true only when every element passes the modulo test.
const numbers = [2, 4, 6, 8, 10];
const allEven = numbers.every((num) => num % 2 === 0);
console.log(allEven);
// true How It Works
- Start with even numbers. The array is
[2, 4, 6, 8, 10]. - Test each value.
num % 2 === 0is true for every item. - All callbacks pass. No early exit — every slot was checked.
- Result is
true. The whole list satisfies the rule.

