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

330
Visualizações
what is the difference events and tasks?

I am learning event loop, but I don't distinguish terminology about events and tasks.In the event loop context,I can understand "task" in MDN,

tasks are triggered by events.A task is any JavaScript code which is scheduled to be run by the standard mechanisms such as initially starting to run a program, an event callback being run, or an interval or timeout being fired.

Async Tasks are triggered by events. Can I understand that events are tasks that executed in another thread? what is event in the event loop?

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Events are signals that tell the event loop that a task is now ready to run. They are not part of the event loop, they come from outside. Examples are DOM events (such as clicks, keyboard events etc), network events (readystatechange, progress), timer events (from setTimeout). Events are not tasks themselves. They may or may not be fired by another thread - often enough, the event loop polls for them.

about 4 years ago · Santiago Trujillo Relatório

0

Events do not occur in the event loop. When an event is dispatched, the callback function that must be executed is pushed onto the macrotask queue. There is no designated place for events inside the event loop, since events are not functions themselves. (macrotask and task is the same thing)

To give you a concrete example, let's say you have a button and a user clicks that button. When the user clicks that button, the callback function that must be executed is pushed onto the macrotask queue and when the call stack is completely empty the event loop will push the callback function from the macrotask queue onto the call stack. There is also a microtask queue but I don't want to confuse you.

I suggest reading the following articles that perfectly describe the event loop in chrome and how it works:

  • https://towardsdev.com/event-loop-in-javascript-672c07618dc9
  • https://blog.insiderattack.net/javascript-event-loop-vs-node-js-event-loop-aea2b1b85f5c
  • https://www.youtube.com/watch?v=28AXSTCpsyU&ab_channel=TraversyMedia ( I don't quite agree with everything he says, but it's a good starting point. I suggest reading the articles first. )
about 4 years ago · Santiago Trujillo 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