Ready. Start with one instruction.
Loading the learning workspace…
FROM YOUR FIRST INSTRUCTION TO A WORKING APPLICATION
Learn JavaScript from scratch through small working examples, visual experiments and complete projects. No account or AI key required.
Predict → Experiment → Build → Test → Explain
Ready. Start with one instruction.
Loading the learning workspace…
The event loop coordinates tasks and microtasks while ordinary code still runs synchronously within the current task. The classic prepared example prints A, D, C, B. A zero-delay timer does not interrupt the current task. The already-resolved promise schedules its then callback for a microtask checkpoint before the timer task runs. Our worker captures actual console order; queue diagrams are simplified educational models and do not inspect hidden engine queues.
console.log("A");
setTimeout(() => { console.log("B"); }, 0);
Promise.resolve().then(() => { console.log("C"); });
console.log("D");A D C B
Synchronous logs run first. The promise callback is a microtask, and the timer callback is a later task. The timer delay is a minimum scheduling request, not a guarantee of immediate execution.
console.log("A");Evaluate the argument and display its value at this point. Quoted text is literal; an unquoted identifier reads its current binding.
setTimeout(() => { console.log("B"); }, 0);Evaluate the argument and record its current value in the console. This observation does not change the application state.
Promise.resolve().then(() => { console.log("C"); });Evaluate the argument and record its current value in the console. This observation does not change the application state.
console.log("D");Evaluate the argument and display its value at this point. Quoted text is literal; an unquoted identifier reads its current binding.
console.log("Start");
setTimeout(() => { console.log("B"); }, 0);
Promise.resolve().then(() => { console.log("C"); });
console.log("D");Start D C B
Synchronous logs run first. The promise callback is a microtask, and the timer callback is a later task. The timer delay is a minimum scheduling request, not a guarantee of immediate execution.
console.log("Start");Evaluate the argument and display its value at this point. Quoted text is literal; an unquoted identifier reads its current binding.
setTimeout(() => { console.log("B"); }, 0);Evaluate the argument and record its current value in the console. This observation does not change the application state.
Promise.resolve().then(() => { console.log("C"); });Evaluate the argument and record its current value in the console. This observation does not change the application state.
console.log("D");Evaluate the argument and display its value at this point. Quoted text is literal; an unquoted identifier reads its current binding.
console.log("First");
setTimeout(() => { console.log("B"); }, 0);
Promise.resolve().then(() => { console.log("C"); });
console.log("D");First D C B
Synchronous logs run first. The promise callback is a microtask, and the timer callback is a later task. The timer delay is a minimum scheduling request, not a guarantee of immediate execution.
console.log("First");Evaluate the argument and display its value at this point. Quoted text is literal; an unquoted identifier reads its current binding.
setTimeout(() => { console.log("B"); }, 0);Evaluate the argument and record its current value in the console. This observation does not change the application state.
Promise.resolve().then(() => { console.log("C"); });Evaluate the argument and record its current value in the console. This observation does not change the application state.
console.log("D");Evaluate the argument and display its value at this point. Quoted text is literal; an unquoted identifier reads its current binding.
Repair the intentionally changed operation so the example produces the exact expected result. Then try the extension without copying the answer.
console.log("A");
setTimeout(() => { console.log("B"); }, 0);
Promise.resolve().then(() => { console.log("C"); });
console.log("B");console.log("A");
setTimeout(() => { console.log("B"); }, 0);
Promise.resolve().then(() => { console.log("C"); });
console.log("D");Predict the output before running the example.
Which operation changed the result, why did it work, and what would you test next?
Use a different value that could expose a boundary or mistake. Predict the result first, run it, and explain how the concept would help in a small real application.
Related: Previous lesson Next lesson
100 lessons across 20 modules, covering variables, operators, strings, conditions, loops, functions, scope, arrays, objects, DOM, events, state, testing, asynchronous JavaScript and application development.