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

226
Vistas
Microtask Queue waits for all operations to be performed before moving to the callstack?

As far as I understood, I expected them to be printed according to the resolution time of each one (after the callstack is empty), to finally print the setTimeout() message.

However, all solutions are printed when the most time-consuming task is completed. Specifically, it is only when the promise operation of the second call to recursionSecond() is completed that all the others are also printed.

    setTimeout(() => console.log('timeout in 0'), 0);
    
    function recursionFirst(number) {
        return new Promise((resolve, reject) => {
            for(let i = 0; i > (number * (-1)); i--) {
                if(i === (number * (-1)) + 1) resolve(i)
            }
        })
    }
    
    function recursionSecond(number) {
        return new Promise((resolve, reject) => {
            for(let i = 0; i < number; i++) {
                if(i === number - 1) resolve(i)
            }
        })
    }
    
    recursionFirst(40) 
        .then(x => console.log(x))
    
    recursionFirst(400) 
        .then(x => console.log(x))
    
    recursionFirst(400) 
        .then(x => console.log(x))
    
    recursionSecond(10) 
        .then(x => console.log(x))
    
    recursionSecond(2000000000) 
        .then(x => console.log(x))
    
    recursionSecond(1000) 
        .then(x => console.log(x))
    
    console.log("Hi!")

about 4 years ago · Juan Pablo Isaza
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