title: JavaScript - Setting variables
body: <p>In the following JavaScript code, the value that is being returned by function(result) is correct. So I'm seeing two alert views - one with the correct value and the second alert simply returns 1. So my question is - how do I conserve the value of mainResult so that it shows the same output ?</p>
  
  <pre><code>var mainResult = 1;
  Download.beginDownload(arr,
         function(result){
            mainResult = result;
            alert(result);
            }, function(result){
                  alert("here2");
                  console.log(result);
            }
   );
  
  
  alert(mainResult);
  </code></pre>