title: bcrypt.compare() is asynchronous, does that necessarily mean that delays are certain to happen?
body: <p>I'm using the <a href="https://www.npmjs.com/package/bcryptjs" rel="nofollow noreferrer">bcryptjs</a> package to hash and compare passwords.</p>
  
  <p>The <code>compareSync</code> method used below is synchronous and returns a boolean.  It is reliable and works as expected.</p>
  
  <pre><code>let trueOrFalse = bcrypt.compareSync('abcd', '1234');
  
  if(trueOrFalse) {
      console.log('hooray, it was true');
  } else {
      console.log('oops, it was false');
  }
  </code></pre>
  
  <p>The next example uses the asynchronous <code>compare</code> method.  I'm concerned that because this version is async if there is any delay on the server it may get to the <code>if/else</code> statement before <code>bcrypt.compare</code> has determined the value of <code>res</code>.  Is this a valid concern or am I misunderstanding the nature of this type of async function?</p>
  
  <pre><code>let trueOrFalse;
  bcrypt.compare('abcd', '1234', function(err, res) {
      trueOrFalse = res;
  }
  
  if(trueOrFalse) {
      console.log('hooray, it was true');
  } else {
      console.log('oops, it was false');
  }
  </code></pre>