JS Built-ins
← Array54 / 226
ArrayArray.prototype.everybeginner

Array.prototype.every() β€” vacuous truth

πŸ“– Usage Example
const empty = []
empty.every(x => x > 0)  // β†’ true  (vacuous truth)

every() returns true for empty arrays β€” there are no elements to violate the condition.

Array.prototype.every() β€” empty arrays

By mathematical convention, [].every(anything) always returns true. This is called vacuous truth β€” there are no elements to violate the condition.

Challenge: Implement isEveryLong(strs) that returns true if every string has length > 5. Observe that an empty array returns true.

isEveryLong(['hello world', 'goodbye']) // β†’ true
isEveryLong(['hi'])                     // β†’ false
isEveryLong([])                         // β†’ true
πŸ’‘ Hints (2)
  • β€’ This is intentional JavaScript behavior β€” `[].every()` always returns `true`.
  • β€’ Think of it as: "there are no elements that fail the condition".