title: Confusion between a general global variable and object as a variable in javaScript
body: <p>Below is my code. When I'm calling <code>myDate</code> variable outside of <code>myTime()</code> function to create a <code>Date()</code> object, the <code>setInterval()</code> function don't fire but when it's inside <code>myTime()</code> function. As I know <code>myDate</code> variable is a global variable and it should work same inside or outside of the function. But why here the <code>setInterval()</code> method not firing while I'm creating the <code>Date()</code> object outside of the function? Experts explain the things. TIA</p>
  
  <pre><code>var myDate = new Date();
      function myTime(){
          document.getElementById('text').innerHTML = myDate.getHours() + ":" + myDate.getMinutes() + ":" + myDate.getSeconds();
      }
      setInterval(myTime, 1000);
  </code></pre>