0

I have this code that is not behaving as I expect it to. I've looked at several other questions, but the context seems not to be the same, so I'm asking a new one.

async function loadDefaultConfig() {
    const response = await fetch("defaultSettings.json");
    console.log(response.json());
}

This is printing Promise { <state>: "pending" } in Firefox, but I was expecting not expecting to get a Promise after using await. How is await supposed to be used here in order to log the actual result of the fetch?

A. R.
  • 2,031
  • 13
  • 27
  • 1
    Long story short: Also `await` `response.json()`. – Ivar Jan 25 '21 at 20:54
  • Or do `const responseObj = await fetch(...).then(r => r.json());` edit: fixed silly mistake –  Jan 25 '21 at 20:56
  • @lvar Thank you, that is... unintuitive, to say the least. I would never have guessed that my problem was actually the `.json()` and not the `await` not doing what I expected. – A. R. Jan 25 '21 at 20:56

0 Answers0