I've recently started learning Javascript and I'm currently going through chapter 5 of Eloquent Javascript. In my studies, I encountered a piece of code that is puzzling to me. While I understand the general method and steps of how it works, I'm struggling to grasp why it works.
Here's the code snippet in question:
function filter(array, test) {
var passed = [];
for (var i = 0; i < array.length; i++) {
if (test(array[i]))
passed.push(array[i]);
}
return passed;
}
Essentially, the function takes each element being iterated over by the 'for loop' from the array and compares it to the test parameter.
My confusion lies with this part of the code:
if (test(array[i]))
There are no obvious comparison operators such as || or &&. How does it compare values using just parentheses?
How exactly does test get compared to the value of array[i] without any explicit operators?
If you'd like to access the file, here's the link: . Navigate to the 'Filtering an Array' exercise.
Thank you!