There is a code of the function "filter" for filtering the array "arr", according to the results of the execution of the function "func".
function filter(arr, func) { var result = []; for (var i = 0; i < arr.length; i++) { var val = arr[i]; if (func(val)) { result.push(val); } } return result; } function inBetween(a, b) { return function(x) { return x >= a && x <= b; }; } var arr = [1, 2, 3, 4, 5, 6, 7]; alert( filter(arr, inBetween(3, 6)) ); // 3,4,5,6 Please explain how val=arr[i] is passed to x .