Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

277
Views
TypeError [ERR_INVALID_CALLBACK]

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.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use setTimeout or setInterval for that directly. All the params after the delay param, will be passed to the callback function in the same order :)

let cb = function(x) {
  console.log(x);
};

const doShortly = function(callback, delay, data) {
  let result = setTimeout(callback, delay, data);
  return result;
};

console.log(doShortly(cb, 500, 'hi')); // or: setTimeout(cb, 500, 'hi')

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!