title: setInterval function returning undefined
body: <p>I am learning setInterval in JavaScript for the first time, and am trying to show a value after 5 seconds. My code is given below:</p>
  
  <pre><code>&lt;button onclick="myTest()"&gt;Try it&lt;/button&gt;
  
  &lt;script&gt;
  function myTest() {
      const ret = myFunction();
      alert(ret);
  }
  
  function myFunction() {
      let i = 0;
      const interval = setInterval(function(){ 
          i += 1;
          if (i === 5) {
              clearInterval(interval);
              return i;
          }
      }, 1000);
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>I want 5 to be alerted, instead I am getting <code>undefined</code>. Does anyone know why this is happening? Thanks in advance!</p>