reactjs – React.js vs Javascript variable declaration

I have here a code using React.js, this code returns undefined in the console..

getTicket = async() =>{
    var ticketData;
    this.state.client.get('ticket').then(
        await function(data){
            ticketData = data['ticket'].toString();
            console.log(data['ticket'])
        
        }
    )
    await this.setState({ ticketInformation: ticketData })
}

while this one is javascript, this code returns the value of ticketData..

  var ticketData;
  client.get('ticket').then(
    function(data) {
      ticketData = data['ticket'];
      console.log("TICKET:: " + JSON.stringify(ticketData.id));
    }
  );

my question is, what is the difference between the 2? on the first code as you can see, I am using a async/await which should not return undefined as far as I know.. Somehow the 2nd code has no async/await but fully giving a value to the global variable.

Read more here: Source link