Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

207
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda