title: How to access to the variable inside a fetch function that the result was assigned to and use it
body: <pre><code>export async function getPlayers() {
    try {
      const receivedData = await fetch(url);
      const body = await receivedData.json();
      console.log(body);
    } catch (error) {
      console.log(error);
    }
  }
  </code></pre>
  <p>Here is my function to get and save result into a variable named body.
  How can I access to the body outside the function?
  I tried this but didnt work.</p>
  <pre><code>let result;
  export async function getPlayers() {
    try {
      const receivedData = await fetch(url);
      const body = await receivedData.json();
      result = body;
    } catch (error) {
      console.log(error);
    }
  }
  </code></pre>
  <p>console.log(result)</p>
  <p>I get undefined when I run it.</p>
  <p>what is the bes practice?</p>