some and every: Yes-or-No Questions

Grade 10, page 6 of 12. A one-minute read.

These two answer questions about the whole array, and return a simple true or false:

  • some: "Does at least one item pass the test?"
  • every: "Do all the items pass the test?"
JavaScript
const scores = [72, 85, 49, 91];

console.log(scores.some((s) => s < 50));
console.log(scores.every((s) => s >= 50));
console.log(scores.every((s) => s > 0));

It prints

true
false
true

Is anyone failing? Yes (some found the 49). Is everyone passing? No. Are all scores positive? Yes.

JavaScript
const cart = [
  { item: "rice", inStock: true },
  { item: "oil", inStock: true },
  { item: "sugar", inStock: false },
];

if (cart.every((product) => product.inStock)) {
  console.log("✅ Ready to check out!");
} else {
  console.log("⚠️ Some items are out of stock.");
}

It prints

⚠️ Some items are out of stock.

Reading is step one

CurlyScript turns these notes into a game: short questions, an explanation after every answer, and a test at the end of each grade. Free, with nothing to sign up for.

Start learning