title: executing code inside setTimeout in a asynchronous function?
body: <p>A simple script, what I am trying to achieve is pushing new item in the append method, and using asynchronous functions</p>
  <p>I'm trying to understand how then and catch works instead of using them without understanding how they work inside ( using axios or something )</p>
  <p>The push has to be executed after 3 seconds</p>
  <p>I tried to use the resolve method inside <code>setTimeout</code> but I am getting an error, because <code>resolve</code> isn't recognized, I am returning a Promise because I can't await a <code>setTimeout</code></p>
  <pre><code>&lt;script&gt;
  
      async function test(terms) {
          let termss = await append(terms);
          return [termss[termss.length - 2], termss[termss.length - 1]]
      }
  
      async function append(arr) {
          var arrr = arr;
  
          const waitFor = () =&gt; new Promise(resolve =&gt; {
              setTimeout((resolve) =&gt; {
                  arrr.push(&quot;Taoufiq&quot;)
                  arrr.push(&quot;understands&quot;);
              }, 3000)
          });
  
          await waitFor();
  
          return arrr;
      }
  
      test([1, 2, 3, 9]).then((result) =&gt; {
          console.log(result)
      })
  
  &lt;/script&gt;
  </code></pre>
  <p>Ayy help on this to understand how this works ?</p>
  <p>My expected result is returning an array with <code>[&quot;Taoufiq&quot;, &quot;understands&quot;]</code></p>