title: JavaScript function returning undefined but both cases are defined
body: <p>My function returns undefinded but the return value is defined.</p>
  <pre><code>function createcode() {
              var clientid = interaction.user.id;
              var sqlsearch = `SELECT COUNT(*) AS count FROM codes WHERE ClientID = '${clientid}'`
              database.query(sqlsearch, code, function(err, rows)  {
                  if (err) throw err;
                  var count = rows[0].count;
                  if(count != 0)
                  {
                      var exsitingcode;
                      var getexsitingcode = `SELECT codes, codes AS ecode FROM codes WHERE ClientID = '${clientid}'`;
                      database.query(getexsitingcode, async function(err, rows)  {
                          if (err) throw err;
                          exsitingcode = await rows[0].ecode;
                          console.log(`${interaction.user.username} tried creating a code but already has one: ${exsitingcode}`)
                          return exsitingcode;
                      })
                  }
                  else
                  {
                      var code = Math.random().toString(36).slice(3);
                      var sql = `INSERT INTO codes(codes, ClientID) VALUES ('${code}', '${clientid}')`
                      database.query(sql, function(err)  {
                          if (err) throw err;
                          console.log(`Inserted Code: ${code}`)
                          setTimeout(() =&gt; {
                              var sqldelete = `DELETE FROM codes WHERE codes = '${code}'`
                              database.query(sqldelete, function (err) {
                                  if (err) throw err;
                                  console.log(`Code deleted: ${code}`);
                              })
                          }, 300000); // 5Min
                          console.log(&quot;returning code...&quot;)
                          return code;
                      })
                  }
              })
          }
  </code></pre>
  <p>In both cases it returns undefinded. How can I bypass this?</p>
  <p><em>using mysql &amp; discord.js v13</em></p>