title: Variables not changing it's values - Function returning promise - JavaScript
body: <p>So I'm making a function for every time I need to work with my database SQLite I give to this function 3 parameters and then it returns for me the result.</p>
  <p>The problem is the function is returning a promise, and also I tried to update the value of some variables and they don't change:</p>
  <p>Let me show you my code, and then to explain you better about what I'm having trouble with:</p>
  <pre><code>       //Down here I'm using the function I made, I'm passing as parameters my  
         // connection, my SQL string, and my arguments
  
          (Main.js)
          const resultSQL = sqlExecute(db,'SELECT * FROM tbl_diarys',[]);
          console.log(resultSQL)
  
  ----- // Now this down here is the function I made------------------------------------------------------
  
        const { Alert } = require(&quot;react-native&quot;)
  
        const sqlExecute = async (dbConection,sqlQuery,arg,)=&gt; {
  
        let resultSQL = []
        let test = 'x' // variable that i created to make a test changing it's value  
            
  
             await dbConection.transaction((tx)=&gt;{
                tx.executeSql(sqlQuery,arg,(tx,results)=&gt;
                 {
                  Alert.alert('', 'SQL executed with success')
  
                    var len = results.rows.length;
                    var vectorResults = []
  
                    for (let i=0; i&lt;len; i++){
                    let row = results.rows.item(i);
                    vectorResults.push(row)
                    }
  
              console.log(vectorResults) // Showing the results from my database
  
              test = 'y' // trying to change the value of variable &quot;test&quot;  from 'x' to 'y'
  
              resultSQL = [...vectorResults]; // cloning my results from database to my variable resultSQL
  
          },(error)=&gt;{Alert.alert('Some error had happened'); console.log(error)})
      })
  
  
      console.log(test) // showing the value of my variable &quot;test&quot;
  
      console.log(resultSQL) // showing the value of my variable resultSQL
  
      return (resultSQL);
      
  }
  
  module.exports=sqlExecute
  
  </code></pre>
  <p>THIS IS MY CONSOLE.LOG
  <a href="https://i.stack.imgur.com/4LJAh.jpg" rel="nofollow noreferrer">this is a picture of my console.log</a> &lt;----------------------------------</p>
  <p>So my questions are:</p>
  <p>1º Why my variable &quot;test&quot; never changed it's value to 'y'?</p>
  <p>2º Why my function is returning a promise? since I put to return the variable resultSQL?</p>
  <p>3º Why my variable <code>resultSQL</code> also never changed it's value to my database results?</p>
  <p>As you guys can see my connection with the database is working well returning a vector with results of my SQL query, but I can't manage to return this vector, instead my function is returning a promise.</p>
  <p>Thank you guys for helping me, I wish you all a great day!</p>