title: Closing showWaitScreenWithNoClose in SharePoint CSOM
body: <p>I am creating a list using REST APIs. In my JavaScript code I have written something like this:</p>
  
  <pre><code>// If I declare 'waitDialog' then it is not get closed by 
  // calling 'waitDialog.close()'. Without any declaration it works.
  var waitDialog;
  
  function createList() {
  
      // Show wait dialog
      waitDialog = SP.UI.ModalDialog.showWaitScreenWithNoClose("Please wait...", "Please wait...", 100, 300);
  
      jQuery.ajax({
          // List data
          },
          success: doSuccess,
          error: doError
      });
  }
  
  function doSuccess(data) {
      waitDialog.close(); // Close wait dialog
  }
  
  function doError(data, errorCode, errorMessage) {
      waitDialog.close(); // Close wait dialog
  }
  </code></pre>
  
  <p>If I declare <code>waitDialog</code> with statement <code>var waitDialog;</code> then it does <em>not</em> work by calling <code>waitDialog.close()</code>. Without any declaration it works and the dialog is closed. I found <a href="https://stackoverflow.com/q/1470488/1047998">this question</a> which elaborates on the difference between using <code>var</code>, but nothing which would clarify this case.</p>
  
  <p>Any idea why does it work without declaration and not with declaration? </p>