Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

129
Visualizações
Does setTimeout get added to the call stack?

I've been learning about setTimeout and synchronous versus asynchronous code, I was watching a tutorial video where they showed various functions being called and added to the call stack, e.g. a function to simply add 2 numbers.

However for setTimeout they didn't show that when this was invoked that it was being added to the call stack, I understand that this fires up a web API and that the callback is added to a queue but I'm curious if in the moment that setTimeout is being executed by the JS engine, is it added to the call stack or not?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

in the moment that setTimeout is being executed by the JS engine, is it added to the call stack or not?

It is. And it is popped from the call stack as soon as the callback is registered, so this hardly takes any time.

When the given delay has passed, the callback will be queued. Then when the call stack is empty, JS will process the event queue, and the callback will be called. Also this callback will be added to the call stack.

Just note that setTimeout and the callback will not be added to the call stack cumulative. It is guaranteed that the call stack will be emptied first before the callback will be pushed unto it.

about 4 years ago · Juan Pablo Isaza Relatório

0

Yes, after the time set in timeout passes, the callback is pushed to the call stack & executed.

Actually, the only way for a JS function to execute is to pass through the call stack.

Here is a good visualization tool called loupe by Philip Roberts that may help in understanding the call stack & things related to it.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda