Practice & Assessment
Test your understanding of Asynchronous JavaScript
Multiple Choice Questions
5What is the output order? console.log("A"); setTimeout(() => console.log("B"), 0); Promise.resolve().then(() => console.log("C")); console.log("D");
What does fetch return when a server responds with a 404 status code?
What happens when one Promise rejects inside Promise.all()?
What does an async function ALWAYS return?
What is the purpose of AbortController with fetch?
Coding Challenges
1Async Retry Wrapper
Write a function retry(asyncFn, maxAttempts, delayMs) that calls asyncFn(), and if it rejects, waits delayMs milliseconds and tries again up to maxAttempts total tries. If all attempts fail, reject with the last error. If it succeeds on any attempt, resolve with the result. Input: asyncFn is a function returning a Promise, maxAttempts is a positive integer, delayMs is a positive integer. Use async/await and a loop. Time estimate: 25 minutes.
Mini Project
GitHub Repository Explorer
Build a Node.js CLI tool that fetches data from the public GitHub API. The user passes a GitHub username as a command-line argument (process.argv[2]). The tool should: (1) fetch the user's public profile from https://api.github.com/users/{username}, (2) fetch their public repositories in parallel using Promise.all, (3) display name, bio, follower count, and the top 5 repos sorted by stars (include name, description, star count), (4) implement a 5-second timeout using Promise.race and AbortController that prints a 'Request timed out' message. Handle all error cases: user not found (404), network errors, and malformed responses. Use async/await throughout with proper try/catch.
