title: Do JavaScript engines create a new lexical environment for closures ?
body: <p>When we have an inner function that access a variable <code>x1</code> defined in the lexical environment of its outer function, how the JavaScript engines handle keeping the <code>x1</code> in the memory ?</p>
  
  <p>Do they keep the already created execution context with its lexical environment of the outer function or they create a new lexical environment and copy the variable binding into it then link it as the <code>outer</code> lexical environment for the lexical environment of the inner function and destroy the execution context with the lexical environment of the outer function.</p>
  
  <p>Can we consider a <code>closure</code> as a <code>Lexical Environment</code> ?</p>
  
  <ul>
  <li>The outer function is <code>func1</code>.</li>
  <li>The inner function is <code>func2</code>.</li>
  <li>The outer variable is <code>x1</code> defined inside <code>func1</code>.</li>
  </ul>
  
  <p>In the following code:</p>
  
  <pre><code>function func1() {
  
    var x1 = 1;
  
    return function func2() {
  
      var x2 = 2;
  
      return [x1, x2];
  
    }
  
  }
  
  func1()();
  </code></pre>