I came across the .every() method today and found this example code to explain how it works:
var ages = [32, 33, 16, 40];
function checkAdult(age) {
return age >= 18;
}
function myFunction() {
document.getElementById("demo").innerHTML = ages.every(checkAdult);
}
The result of myFunction()
is false
, and I understand what the method is doing (going through each value of the array and checking if the value is >= 18
, but I don't understand how the .every()
method is able to use the age
parameter in its return statement without age
being declared in the method call.
Does the method somehow automatically know that it should be referencing the index of the array it's looking at? That's the only explanation I can come up with, but I can't find any explanation of this online.