Question from the Javascript - Fundamentals test

Write a JavaScript function that fetches data from an API and logs it to the console.

Medium

What is the output of the following JavaScript code?

function fetchData() {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve("Data fetched!");
    }, 1000);
  });
}

async function displayData() {
  const data = await fetchData();
  console.log(data);
}

displayData();
console.log("After displayData call");
Author: Vincent CotroStatus: PublishedQuestion passed 2703 times
Edit
31
Community EvaluationsNo one has reviewed this question yet, be the first!