title: How to put fetch data in a variable
body: <p>I have a code that results <code>undefined</code> whenever I try fetch results into a variable</p>
  
  <pre><code>var data;
  fetch('./js/samplejson.json')
      .then((res) =&gt; res.json())
      .then(output =&gt; {
          var data = output;
      } 
  )
  console.log(data);
  </code></pre>
  
  <p>How can I get a result of </p>
  
  <pre><code>[1, 2, 3]
  </code></pre>
  
  <p>inside data variable</p>