title: Defining variables within JavaScript Promise Declaration as opposed to outside
body: <p>I'm just trying to get my head around JavaScript Promises and I'm confused about something.</p>
  
  <p>What is the difference between the following two functions?</p>
  
  <pre><code>function func_1()
  {
       var myArgs = Array.prototype.slice.call(arguments),
          arg_1 = (myArgs[1]) ? myArgs[1] : 1,
          arg_2 = (myArgs[2]) ? myArgs[2] : 2
          ;
  
      return new Promise(function(resolve, reject) {
          var result = arg_1 + arg_2;
          resolve(result);
      });
  }
  
  function func_2()
  {    
      return new Promise(function(resolve, reject) 
      {
          var myArgs = Array.prototype.slice.call(arguments),
              arg_1 = (myArgs[1]) ? myArgs[1] : 1,
              arg_2 = (myArgs[2]) ? myArgs[2] : 2
              ;
  
          var result = arg_1 + arg_2;
          resolve(result);
      });
  }
  </code></pre>