title: Understanding what happens to variables when passing functions as JavaScript variables
body: <p>OK.  I am trying to understand closure in JavaScript.
  I have a function but I am seeing inconsistent results.  When passing the url parameter it's fine unless it's being done in a callback.  I thought closure would retain that value in the function. </p>
  
  <pre><code>ABC.print = function (reportId, format, reportTitle) {
          alert("Coming in=" + format);  // Always has right value.
  
          var url = 'Main/MyModule/Print?reportId=' + reportId;
          url += '&amp;format=' + format;
          url += '&amp;reportTitle=' + reportTitle;   
  
          function printWindow(urlString) {
             window.open(urlString, 'Print', "toolbar=no,menubar=no,status=no");
          };    
  
          // What is the difference between?
     if (someCondition)
     {
        // Variables in url are not current, they retain first time value only.
        SomeFunction("Text", "Text 2", function () { printWindow(url); });
     }
     else {
        // Variables are always current
        printWindow();
     }
  };
  </code></pre>