title: Assign return value of function to variable
body: <p>I kind of got the same question as has been asked <a href="https://stackoverflow.com/questions/3941381/assign-function-return-value-to-some-variable-using-javascript">here</a>.</p>
  
  <p>I've made a function:</p>
  
  <pre><code>const rewardStayingViewersOrNewcomers = () =&gt; {
    fetch('https://tmi.twitch.tv/group/user/instak/chatters')
    .then(parseJSON)
    .then(r =&gt; {
      let chatters = r.chatters;
      viewerKeys = Object.keys(chatters); // [mods, viewers,...]
      let ChattersPerRole = viewerKeys.map(role =&gt; {
        return chatters[role].map(username =&gt; ({
          username, role
        }));
      });
      return flattenDeep(ChattersPerRole);
    }).catch(err =&gt; {
      console.log(`Error in fetch: ${err}`);
    });
  };
  </code></pre>
  
  <p>Why can't I assign that return value to my variable? The log of that variable returns undefined...</p>
  
  <pre><code>let viewersPerRole = rewardStayingViewersOrNewcomers();
  setTimeout(() =&gt; console.log(viewersPerRole), 7000);
  </code></pre>
  
  <p><em>Bonus question</em>, how could I easily wait for viewersPerRole to be filled with the data I'm waiting for because of the fetch? (so I don't have to use setTimeout())?</p>