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

208
Views
Getting "Uncaught TypeError: callback is not a function" from using timeout with a callback

I want to do a callback with the calculator if successful, and I want it to catch the "Too High" error. But now when it throws the error all i get is "Uncaught TypeError: callback is not a function". No idea what I am doing wrong here

const calculator = (number, callback) => {
  setTimeout(() => {
    try { if (number > 3) Error('Too high')
      callback(null, number);
    } catch (err) {
      callback(err, null);
    }
  }, 888);
};
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I hope you are passing a callback as a param when calling the calculator function. If you want to catch the error Too High what you can do here instead is add the condition to the callback function you're passing as a param to the calculator function and return it from there since here your if condition is returning undefined. Actually, instead of adding the if one-line condition, use the && operator in the callback function, you are passing to return an error if a number is greater than 3. And just like T.J Crowder is saying you use throw Error('Too High').

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!