I highlighted the parameter that I don't understand where its value comes from. Shouldn't the array get passed? it makes no sense. It all feels backwards. How does the array values get into the ages.some(checkAdult)
invocation? Does the keyword before the dot become the argument that I imagine should be in parenthesis after checkAdult
?
Why doesn't it go some(checkAdult(ages))
?
Why append it to the end of something with a dot?
var ages = [3, 10, 18, 20];
function checkAdult(age) { // THIS LINE HERE, how does it link to the array???
return age >= 18;
}
function myFunction() {
document.getElementById("demo").innerHTML = ages.some(checkAdult);
}
<p>Click the button to check if any of the elements in the array has a value of 18 or more.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>