title: Use same variable that is defined in another function
body: <p>This may seem simple to some but I am less experienced with JavaScript. I have two functions. One is called when my upload begins. The next is called when my upload ends.</p>
  
  <p>In the first function, a variable is created, a unique id used for the upload. What is the best way to go about reusing it in my second function since it is not global? The reason I defined it within my function is because every time a user clicks the upload button, the function is called and a NEW id is created for that upload, that is why I do not want to define it outside because then the same id would be served for a second upload unless the page is refreshed.</p>
  
  <p>Anyone got any suggestions?</p>
  
  <pre><code>function uploadstart() {
  
      function makeid() {
          var text = "";
          var possible = "abcdefghijklmnopqrstuvwxyz0123456789";
  
          for( var i=0; i &lt; 32; i++ )
              text += possible.charAt(Math.floor(Math.random() * possible.length));
  
          return text;
      }
  
      var rand_id = makeid();
  
  }
  
  uploadfinish(){
      //rand_id will be undefined
  }
  </code></pre>