title: How Closure gets set in Web API call?
body: <p>I was not getting how a closure  variable gets attached to function ([[Scope]]) when making a Web API request like for timer (serTimeout).</p>
  
  <pre><code>function fun() {   
      function log() {console.log(callme) }; 
      console.dir(log); 
      setTimeout( log, 10000);
      const callme = "hi iam"
    }
  fun()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/1GCU8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1GCU8.png" alt="enter image description here"></a>
  function <em>log</em> gets access to variable <em>callme</em> when const do not get hoisted.</p>
  
  <p>My thinking is that <em>fun()</em> is called , it is pushed to call stack , function <em>log</em> is then sent to WebAPI timer function , in the mean time <em>fun</em> gets run and sets <em>callme</em> variable in its execution context. Once Timer is over , fn <em>log</em> is pushed to callback queue and event loop after checking if call stack is empty pushes <em>log</em> to callstack for execution. I am not able to get the idea when <strong>callme</strong> gets attached to closure <strong>[[Scope]]</strong> of function <em>log</em></p>