0

why is this code returning a promise instead of an object?

const getJSON = function (url, errorMsg = "Something went wrong") {
  return fetch(url).then((response) => {
    if (!response.ok)
      throw new Error(errorMsg+". Error Code: "+response.status);

    return response.json();
  });
};
  • Because `.json()` always returns a promise. Why would it return an object? https://developer.mozilla.org/en-US/docs/Web/API/Response/json – VLAZ Oct 27 '21 at 05:17

0 Answers0