Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Array.prototype.every: testing every visited element

every returns true when the callback is truthy for every existing element; an empty array satisfies the condition.

Version: ECMAScript 2026 draft; example target: Node.js 24.22.2

Syntax

array.every(callbackFn[, thisArg])

array.every(callbackFn[, thisArg]) calls callbackFn(value, index, array) in order and stops immediately at the first falsy result, returning false. If none occurs it returns true; the empty-array result is vacuous truth. thisArg supplies this to an ordinary function, but not to an arrow function.

Length is captured before the first callback. Holes are skipped, while a value is read only when its index is visited, so an earlier mutation can be observed. Elements appended beyond the initial length are not tested. A non-callable callback or a null/undefined receiver throws TypeError. The example counts visits, exposes a skipped hole, and checks an empty array.

Examples

const values = [2, , 4];
let visits = 0;
console.log(values.every(value => { visits++; return value % 2 === 0; }));
console.log(visits);
console.log([].every(() => false));

Result

true
2
true

Sources