I want to Implement a function which can run a given function after a delay.
Arguments:
- callback: the function to execute after the delay
- delay: number of milliseconds to wait
- data: the one (and only) argument to pass to the callback
And this was my code
let cb = function(x) {
console.log(x);
};
const doShortly = function(callback, delay, data) {
let result = setTimeout(callback(data), delay);
return result;
};
console.log(doShortly(cb, 500, 'hi'));
I get TypeError [ERR_INVALID_CALLBACK] when I run the code. May I know how to fix this. TIA.