title: Variable set by await is undefined after await expression evaluated
body: <p>I have some code that's using async/await that is giving me a very odd problem: the variable that I set with an await statement is throwing an undefined reference rrror after the expression! Here's the code:</p>
  
  <pre><code>export const fetchPrices = async ({ commit }, ticker) =&gt; {
    const key= "*********";
    const url =
      `http://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&amp;symbol=${ticker}&amp;interval=1min&amp;apikey=${key}`
  
    commit(FETCH_PRICES_REQUEST, { ticker })
  
    try {
      let response = await fetch(url);
      let priceData = await response.json();
    }
    catch (e) {
      console.error(e);
    }
  
    commit(FETCH_PRICES_SUCCESS, priceData)
  };
  </code></pre>
  
  <p>When this runs, the last line of the function throws a couple of errors:</p>
  
  <blockquote>
    <p>ReferenceError: response is not defined</p>
  </blockquote>
  
  <p>and </p>
  
  <blockquote>
    <p>Uncaught (in promise) ReferenceError: priceData is not defined</p>
  </blockquote>
  
  <p>This does not make a whole lot of sense to me as my understanding is that the whole usage of await is that the assignment to the variable should have been completed by the next line of code.</p>
  
  <p>I actually worked out the fix for this, which had to do with where I'd declared the variables. When I moved the declaration outside of the try/catch block by placing the following line at the top of the function, it worked:</p>
  
  <pre><code>let response, priceData;
  </code></pre>
  
  <p>Getting curious, I looked at the transformed code in Babel. With the declaration at the top of the file, it looks like this:</p>
  
  <pre><code>"use strict";
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  
  function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
  
  var fetchPrices = exports.fetchPrices = function () {
    var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(_ref2, ticker) {
      var commit = _ref2.commit;
      var response, priceData, key, url;
      return regeneratorRuntime.wrap(function _callee$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              response = void 0, priceData = void 0;
              key = "EH6GPZQ5X8EUM3MC";
              url = "http://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&amp;symbol=" + ticker + "&amp;interval=1min&amp;apikey=" + key;
  
  
              commit(FETCH_PRICES_REQUEST, { ticker: ticker });
  
              _context.prev = 4;
              _context.next = 7;
              return fetch(url);
  
            case 7:
              response = _context.sent;
              _context.next = 10;
              return response.json();
  
            case 10:
              priceData = _context.sent;
              _context.next = 16;
              break;
  
            case 13:
              _context.prev = 13;
              _context.t0 = _context["catch"](4);
  
              console.error(_context.t0);
  
            case 16:
  
              commit(FETCH_PRICES_SUCCESS, priceData);
  
            case 17:
            case "end":
              return _context.stop();
          }
        }
      }, _callee, undefined, [[4, 13]]);
    }));
  
    return function fetchPrices(_x, _x2) {
      return _ref.apply(this, arguments);
    };
  }();
  </code></pre>
  
  <p>The key difference is the line at the top of the first case (<code>case 0</code>):</p>
  
  <pre><code>response = void 0, priceData = void 0;
  </code></pre>
  
  <p>What seems to happen is if you don't declare the variables at the top of the function, then cases 7 and 10 fail when they try to assign to those variables.</p>
  
  <p>My question is whether or not this is a problem with the async/await compiled code or whether my attempt to declare the variables inside the try/catch block was fundamentally wrong. </p>