The following javascript code works:
const numbers = [10, 15, 20, 25, 30];
function nesting(array, iteratorFunction) {
let f2 = function(b){
return false;
}
return array.filter(
function(a){
return f2(a)
}
);
}
The result is []
when f2 returns false
, and [10, 15, 20, 25, 30]
if f2 is changed to return true
.
Why doesn't it work correctly after this direction substitution where I simply replaced the variable f2 with the original definition of f2?
function nesting(array, iteratorFunction) {
return array.filter(
function(a){
return function(b){
return false;
}
}
);
}
It returns [10, 15, 20, 25, 30]
whether the inner function returns true
or false
. Why? What piece of knowledge of javascript am I missing?