title: Express: Variable not getting rewritten
body: <p>I have this JS code that I've been looking at for the past 2 hours and cannot find the reason why the variable &quot;message&quot; doesn't get rewritten to &quot;User already exists.&quot;. The thing is that &quot;Inside first if&quot; runs, but the variable message doesn't get rewritten to &quot;User already exists.&quot;</p>
  <pre><code>async function postRegister(req, res) {
    const familyName = req.body.familyName;
    const email = req.body.email;
    const password = req.body.password;
    const repeatPassword = req.body.repeatPassword;
  
    let message = 'msg';
  
    // Check if user already exists
    await db
      .promise()
      .query(
        'SELECT * FROM users WHERE email = ?',
        [email],
        function (err, results) {
          if (results.length &gt; 1) {
            console.log('Inside first if');
            message = 'User already exists.';
            return;
          } else {
            if (password !== repeatPassword) {
              console.log('passwords do not match');
            } else {
              const newUser = new User(familyName, password, email);
              newUser.save();
              res.redirect('/login');
            }
          }
        }
      );
    console.log(message);
    res.render('authentication/register', { message: message });
  }
  </code></pre>