title: saving data in javascript classes
body: <p>I'm fetching data from an API and save it in a class.  When I'm trying to output the data in functions it give me an error of <code>undefined</code>, but when I call it in the console i can get the output.</p>
  <pre><code>class Api{
      GetAllRates(){
          async function getData(){
              const Data = await fetch(`https://api.exchangeratesapi.io/latest?`);
              const JData = await Data.json();
              return JData
          }
          getData()
              .then(data=&gt;{
                  this.Jdata = data;
              })
              .catch(err=&gt;console.log(err));
      }
      makeUi(){
          Ui.compareSection(this.Jdata); // TypeError: data is undefined //
      }
  }
  </code></pre>
  <p>I also tried this but I get the <code>{ }</code> as the output</p>
  <pre><code>class Api{
      constructor(){
          this.Jdata = {};
      }
      GetAllRates(){
          async function getData(base=`EUR`){
              const Data = await fetch(`https://api.exchangeratesapi.io/latest?`);
              const JData = await Data.json();
              return JData
          }
          getData()
              .then(data=&gt;{
                  this.Jdata = data;
              })
              .catch(err=&gt;console.log(err));
      }
      makeUi(){
          Ui.compareSection(this.Jdata);
      }
  }
  </code></pre>