×

javascript · level 2 · unit 7 · lesson 2

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

asks a for data, and waits for the reply.

A server is a computer that answers requests over the internet, and fetch(url) sends one. Gwecode answers these lessons with a practice server, so every https://api.example.com/... address in them works here.

Replies take time, so fetch hands back a : a ticket saying the answer is coming. Put await in front and JavaScript waits for the real reply, called a response, before running the next line.

A response's body is JSON text. await response.json() reads it and parses it into objects in one go.

const response = await fetch("https://api.example.com/joke");
const joke = await response.json();
console.log(joke.setup);
console.log(joke.punchline);

Forget await and you get the promise itself, not the reply.