Exercício prático · JavaScript

Practice lab: Predict before running asynchronous code

do caderno de estudos · atualizado em 2 de outubro de 2026
Para quem vai encarar entrevista de JavaScript2 min

Tente resolver a tarefa antes de consultar os critérios. Compare o resultado e explique o que mudou no seu raciocínio.

Tarefa e critérios de verificação

Task, 10 minutes: write an async function that logs before, awaits 42, then logs after. Call it between synchronous logs start and end. Predict the complete output before running it. Next, create two independent counters with the closure example and call them in an alternating order.

Check your work:

  • The first trace is start, before, end, after. Explain the microtask boundary introduced by await.
  • Each counter retains its own binding. Calling one counter must not advance the other.
  • Change one assumption, such as adding a promise callback before the function call, and predict again before execution.

Finish aloud: explain the difference between capturing a live binding and copying a value. A correct trace without an explanation needs another attempt.

No app, a tarefa fica visível e você pode revelar os critérios depois da tentativa. Use as notas para registrar sua solução.

Praticar este exercício no app