JS Built-ins
← Array174 / 226
ArrayArray.prototype.somebeginner

Array.prototype.some() β€” empty array behaviour

πŸ“– Usage Example
const empty = []
empty.some(x => x > 0)  // β†’ false  (no elements to satisfy)

some() returns false for empty arrays since there are no elements to satisfy the condition.

Array.prototype.some() β€” vacuous false

Calling some() on an empty array always returns false, regardless of the predicate. This is called a vacuous truth β€” there are no elements to fail the test, so the result defaults to false.

Challenge: Implement someEmpty() that returns ([] as boolean[]).some(() => true) and observe the result.

someEmpty() // β†’ false
πŸ’‘ Hints (2)
  • β€’ `[].some(predicate)` returns `false` no matter what the predicate does.
  • β€’ Contrast this with `[].every(predicate)`, which returns `true` (vacuously true).