I would like to access 'key' which happens to be a global variable after being returned from this.dorequest(). I get the key inside the if block but can't access it anywhere outside. Can somebody please assist? Pretty sure it is scope/hoisting issue. Thanks in advance!
var key; 
jira.addNewIssue = function(issue) {
  var options = {
      uri: this.makeUri('/issue'),
      method: 'POST',
      followAllRedirects: true,
      json: true,
      body: issue
  };
  this.doRequest(options, function(error, response, body) {
      **var key;** (removed this but still an error)
      if (error) {
          console.log('Error1')
          return;
      }
      else {
          key = response.body.key;
          console.log("THIS IS RESPONSE BODY KEY:", key); //no errors 123
          return key;
      }
  });
};
console.log("hello key", key); //undefined
 
     
     
     
     
    