Skip to content

Come Back Later: Review Challenges

The Course
•
20 min study

After several days

Without reopening the solutions, explain Promise.all versus allSettled; write a decoder rejecting null and malformed records; and trace a then callback relative to a synchronous log. Rebuild one update that preserves its input. These short recall tasks reveal different gaps than recognizing code you just read.

After a few weeks

Build a small quote-preview controller. Only the latest preview may publish, a rejected current request displays an error, and disposal prevents later output. Use a controlled request dependency, not a live API. Test old success, old failure, cancellation, and disposal explicitly. Then connect a form and verify keyboard use.

Use this review as a 20-minute starting session. It is extra practice after the seven-day plan. If a task exposes a missing idea, revisit that lesson and try a new value or schedule after closing the explanation. The suggested intervals are convenient starting points, not a measured optimal spacing schedule.

The course has covered a path from validated data to a maintainable asynchronous app. Further study can explore modules at package scale, asynchronous iterators, workers, performance, and type systems. Do not treat advanced syntax as a substitute for the contracts and tests you can already apply.

Predict and trace

Write the output before running. Follow the values through each call; if your prediction differs, identify the first step that surprised you.

Predict, then run JavaScript
async function main() {
  const order = [];
  const later = Promise.resolve().then(() => {
    order.push("later");
  });

  order.push("now");
  await later;
  console.log(order.join(", "));
}

main();
Check your prediction
Text
now, later

A promise reaction does not interrupt the current synchronous push.

Build it yourself

Exercise

Come Back Later: Review Challenges: practice

Write createPublisher(publish), returning send(text) and dispose(). After disposal no send may call publish, even after repeated disposal. Print only Before from your recorded messages.

Your working space JavaScript
// Rebuild a lifecycle guard from memory.
Hint 1: the idea

One closure flag can protect every publication entry point.

Hint 2: a first step

dispose should set a stable value, not toggle it.

Show one solution
JavaScript
function createPublisher(publish) {
  let disposed = false;

  return {
    send(text) {
      if (!disposed) {
        publish(text);
      }
    },
    dispose() {
      disposed = true;
    }
  };
}

const messages = [];
const publisher = createPublisher(text => messages.push(text));

publisher.send("Before");
publisher.dispose();
publisher.dispose();
publisher.send("After");
console.log(messages.join(", "));
Text
Before

Connect this guard to a deferred async result and resolve it after disposal. Then reject it instead, ensuring the rejection is handled without publishing.

Test a changed requirement

Connect this guard to a deferred async result and resolve it after disposal. Then reject it instead, ensuring the rejection is handled without publishing.

Explain before moving on

Which concepts did you retrieve independently? Name one new schedule you will test in your next project.

Ready for the next step?

Continue to advanced JavaScript when you can explain promise fulfillment versus rejection, inject a controlled dependency, and prevent a stale request from replacing current state. Retry the relevant earlier checkpoint if one of those needs a solution. For static typing, start with TypeScript beginner; if you have already completed it, TypeScript intermediate uses the asynchronous groundwork from this course. JavaScript advanced is not a prerequisite for that TypeScript path.

Was this article helpful?

Your response is saved on this device.