JavaScript async and data quiz

  • Admin
  • 1 min read

Nine questions on JSON, fetch, promises, async/await and localStorage.

JavaScript

JavaScript async and data quiz

9 questions, instant feedback

Question 1 of 9
Question 1 of 9 Which call turns a JSON string into an object?
Why this is the answer

parse reads JSON text into a value. stringify does the reverse.

Question 2 of 9
Question 2 of 9 What does fetch return?
Why this is the answer

fetch resolves once headers are available. You still call response.json() or response.text() to read the body.

Question 3 of 9
Question 3 of 9 What does await do inside an async function?
Why this is the answer

await pauses the async function only. Other work in the page continues.

Question 4 of 9
Question 4 of 9 How do you handle a rejected promise with async/await?
Why this is the answer

A rejection inside an awaited call throws, so try...catch handles it like a synchronous error.

Question 5 of 9
Question 5 of 9 Which check catches an HTTP error status from fetch?
Why this is the answer

fetch rejects only on network failures. A 404 still resolves, so check response.ok or the status.

Question 6 of 9
Question 6 of 9 What does localStorage.setItem require for its value?
Why this is the answer

Storage holds strings, so objects and arrays must be serialised with JSON.stringify.

Question 7 of 9
Question 7 of 9 Which method waits for several promises and returns all results?
Why this is the answer

Promise.all resolves when every promise resolves, and rejects if any rejects.

Question 8 of 9
Question 8 of 9 What does an async function always return?
Why this is the answer

Returning a value from an async function resolves its promise with that value.

Question 9 of 9
Question 9 of 9 Which pattern avoids a flash of empty content while data loads?
Why this is the answer

A visible loading state and an error state make slow or failed requests understandable instead of looking broken.

Your answers stay in this browser. Nothing is sent to a server.