javascript - How to access a local variable inside a callback to outside the function -


im using npm plaid , want able have access variable trans outside plaidclient.gettransactions. thanks

var trans;   var startdate = moment().subtract(30, 'days').format('yyyy-mm-dd');   var enddate = moment().format('yyyy-mm-dd');   plaidclient.gettransactions(accesstoken, startdate, enddate, {     count: 250,     offset: 0,   }, function(error, transactionsresponse) {     if (error != null) {      console.log(json.stringify(error));      return response.json({      error: error      });     }    var trans = transactionsresponse  });    var trans //should work here

you have fundamental misunderstanding of how asynchronous javascript works.

i suggest read 1 of many tutorials on asychronous flow of execution in javascript understand why question asking wrong thing.

a quick google search suggests number of articles on topic.

ex https://www.pluralsight.com/guides/front-end-javascript/introduction-to-asynchronous-javascript


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -