Latihan 1: Event Loop Deep Dive — Node.js

Latihan 1 dari materi Event Loop Deep Dive di Node.js — praktek dengan editor kode interaktif, test case otomatis, dan hint terpandu. Langsung jalan di browser.

Prediksi urutan eksekusi kode yang mencampur kode sync, setTimeout, Promise.then, dan queueMicrotask.

Langkah:

  1. Log "1 sync" (synchronous)
  2. Jadwalkan setTimeout 0 yang log "4 timer"
  3. Log promise "3 promise" via Promise.resolve().then(...)
  4. Log microtask "2 microtask" via queueMicrotask(...) lalu panggil (microtask dulu karena dijadwalkan sebelum promise)
  5. Log "1b sync" sebagai synchronous terakhir

Output yang diharapkan (perhatikan urutan sync → microtask queue → timer):

1 sync
1b sync
2 microtask
3 promise
4 timer

Tulis kode yang menghasilkan urutan ini dan kirim output pakai console.log.

Hint