So I am going back to some of the basics and found that I am having trouble with the simplest of things. I have a callback that is throwing me an error, I suspect this is a hoisting thing, but have been googling and can't seem to find what I am looking for.
function add (a,b){return a+b;}
function multiply (a,b){return a*b;}
function applyFn(callback) {
return callback;
};
var f = applyFn(add);
console.log(f); //logs => function add(a,b){return a+b;}
f(3)(4); // returns => Uncaught TypeError: f(...) is not a function(…)
I know that var f
gets hoisted to the top with a value of undefined, while the named functions are hoisted intact. When I console log console.log(typeof f)
it returns function
- so I am a little confused about what is going on...am I on the right track, or is it a different issue completely?
EDIT:
for more clarity the applyFn was supposed to be able to use either the add
or multiply
function, and so it would look more like this:
function add (a,b){return a+b;}
function multiply (a,b){return a*b;}
//I needed to write this function, but nothing else
function applyFn(callback) {
return function(){};
};
var f = applyFn(add);
var x = applyFn(multiply)
f(3)(4);
x(6)(8);