title: Uncaught TypeError: Cannot read property 'close' of undefined
body: <p>When i compile the following code , it works fine , but in console i get error:
  Uncaught TypeError: Cannot read property 'close' of undefined</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;body&gt;
  
  &lt;button onclick="openWin()"&gt;Open "myWindow"&lt;/button&gt;
  &lt;button onclick="closeWin()"&gt;Close "myWindow"&lt;/button&gt;
  
  &lt;script&gt;
  var myWindow;
  
  function openWin(){
     myWindow = window.open("http://www.w3schools.com", "myWindow");
  }
  
  
  function closeWin() {
      myWindow.close();
  }
  &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var myWindow;
  
  function openWin(){
  
  
      myWindow = window.open("http://www.w3schools.com/", "myWindow");
   
  }
  
  
  function closeWin() {
      myWindow.close();
  
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>i tried to call the above js file externally also, i get the same error</p>