title: How can I make it so that this console.log is executed after the function above it has completed?
body: <p>I am using firebase and I have run into an issue. What I am trying to do is allow a user to sign up, but to check the account doesn't already exist, I want to retrieve all of the usernames from firestore and then search through them to see if their proposed username already exists. Here is my code to do this:</p>
  <pre><code>document.querySelector(&quot;#form1&quot;).addEventListener(&quot;submit&quot;, e =&gt; {
      e.preventDefault();
      var users;
      firestore.collection(&quot;users&quot;).get().then(querySnapshot =&gt; {
          users = querySnapshot.docs.map(doc =&gt; doc.data());
          console.log(users);
      });
      console.log(users);
  });
  </code></pre>
  <p>So I know that when I try to do console.log(users) for the second time, the function above may not have completed its execution which is why when I log it to the console I see &quot;undefined&quot;. How can I change my code so that the second console.log(users) waits for the function above to complete?</p>
  <p>I tried looking into this and found some stuff to do with &quot;async&quot; and &quot;wait&quot; but I couldn't figure out how to make these work in my code. Maybe that could be the solution?</p>