title: ES6 Assign a variable with an arrow function
body: <p>I've just started getting accustomed with ES6 syntax and I was wondering if it was possible to assign to a variable with an arrow function.  I'm writing a basic lightweight AJAX helper library and on a status of 200, I want to return a payload to the user, which I currently do with:</p>
  
  <pre><code>var responseData = "";
  switch (payload.returnType.toLowerCase()) {
      case "json" : responseData = JSON.parse(httpRequest.responseText); break;
      case "text" : responseData = httpRequest.responseText; break;
      default : responseData = null; break;
  }
  callback(null, responseData);
  </code></pre>
  
  <p>This is fine, but I can't help but think I could make this cleaner, if I do:</p>
  
  <pre><code>callback(null, () =&gt; { switch(payload.returnType.toLowerCase()) { ... });
  </code></pre>
  
  <p>I would expect the <code>return</code> statement to send the result of the expression as the 2nd parameter in my callback, however when I console log from the caller it prints the switch statement.</p>
  
  <p>Alternatively I have tried to do:</p>
  
  <pre><code>var responseData = () =&gt; {
      switch (payload.returnType.toLowerCase()) {
          case "json" : return JSON.parse(httpRequest.responseText); break;
          case "text" : return httpRequest.responseText; break;
          default : return null; break;
      }
  }
  callback(null, responseData);
  </code></pre>
  
  <p>In this case, <code>responseData</code> is always empty.  Is it possible to have the return value as my 2nd parameter or have it bound to <code>responseData</code> as the result of the arrow function?</p>