Skip to content

Latest commit

 

History

History
37 lines (24 loc) · 1.01 KB

README.md

File metadata and controls

37 lines (24 loc) · 1.01 KB

33. Event loop and tasks

Explain why asynchronous callbacks run later.

Learn

  • call stack
  • microtasks
  • tasks
  • rendering

How it works

Synchronous code runs on the call stack. Promise reactions run as microtasks after current synchronous work; timers queue tasks for later turns. Rendering happens between suitable turns, so blocking work can delay both callbacks and paint. Predicting order helps debug surprising output.

Common mistake

A zero-millisecond timeout does not interrupt currently running JavaScript.

Guided challenge

Predict the order of logs from synchronous statements, a resolved promise, and a timeout.

Run the example

Open example.html in a browser and edit example.js. Save, refresh, and use the Console and debugger to inspect values.

Completion check

  • Explain the core idea in your own words without reading the code.
  • Change one input and predict the output before running it.
  • Test one boundary or failure case, then record what you changed.