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…
A timer schedules a callback no earlier than the requested delay. The current program does not wait unless you explicitly arrange to wait for a promise representing that completion. This example wraps the timer in a promise, logs from the callback and resolves, then uses await to continue afterward. Timers can run later than requested when other work is active. Use relative ordering for the test rather than claiming an exact elapsed millisecond value.
console.log("Start");
await new Promise(resolve => setTimeout(() => { console.log("Timer"); resolve(); }, 20));
console.log("End");Start Timer End
await yields until the promise resolves. The timer logs its message before resolving, so End follows Timer. This is real execution, not a fabricated timeline.
console.log("Start");Evaluate the argument and display its value at this point. Quoted text is literal; an unquoted identifier reads its current binding.
await new Promise(resolve => setTimeout(() => { console.log("Timer"); resolve(); }, 20));Evaluate the argument and record its current value in the console. This observation does not change the application state.
console.log("End");Evaluate the argument and display its value at this point. Quoted text is literal; an unquoted identifier reads its current binding.
console.log("Start");
await new Promise(resolve => setTimeout(() => { console.log("Timer"); resolve(); }, 0));
console.log("End");Start Timer End
await yields until the promise resolves. The timer logs its message before resolving, so End follows Timer. This is real execution, not a fabricated timeline.
console.log("Start");Evaluate the argument and display its value at this point. Quoted text is literal; an unquoted identifier reads its current binding.
await new Promise(resolve => setTimeout(() => { console.log("Timer"); resolve(); }, 0));Evaluate the argument and record its current value in the console. This observation does not change the application state.
console.log("End");Evaluate the argument and display its value at this point. Quoted text is literal; an unquoted identifier reads its current binding.
console.log("Start");
await new Promise(resolve => setTimeout(() => { console.log("Timer"); resolve(); }, 40));
console.log("End");Start Timer End
await yields until the promise resolves. The timer logs its message before resolving, so End follows Timer. This is real execution, not a fabricated timeline.
console.log("Start");Evaluate the argument and display its value at this point. Quoted text is literal; an unquoted identifier reads its current binding.
await new Promise(resolve => setTimeout(() => { console.log("Timer"); resolve(); }, 40));Evaluate the argument and record its current value in the console. This observation does not change the application state.
console.log("End");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("Start");
new Promise(resolve => setTimeout(() => { console.log("Timer"); resolve(); }, 20));
console.log("End");console.log("Start");
await new Promise(resolve => setTimeout(() => { console.log("Timer"); resolve(); }, 20));
console.log("End");Add one before doubling.
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.