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

112
Vistas
How to call the setTimeout?

I am being given the below mentioned code and asked to print the console after 3 seconds - B and C after A.

I tried

  setTimeout(main(),3000);

But I get no output.

function sleep(){

}

function main(){

console.log('A');

// call after 3 sec
console.log('B');


// call after 3 sec
console.log('C');

}
}
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

setTimeout(main , 3000);

remove function call '( )'

How setTimeout works: You specify the function (as a first argument) to be called after your timeout (second argument: 3000)

about 4 years ago · Juan Pablo Isaza Denunciar

0

Generally you should pass the function by name to the setTimeout function without calling it.

setTimeout(main,3000);

about 4 years ago · Juan Pablo Isaza Denunciar

0

setTimeout(main(), 3000) will execute main immediately because you put the () after it. Just use the name. setTimeout(main, 3000)

Also, you'll want to put your timeout on the two specific log statements you want to call later, not the whole function, or you could also log A outside of the main function and then call the main function after the timeout.

function main() {

  console.log('A');

  // call after 3 sec
  setTimeout(() => {
    console.log('B');
    console.log('C');
  }, 3000);

}

main();

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