javascript - Why is variable inside callback function undefined outside of it? -


this question has answer here:

why eventfb1 undefined outside of graph.get callback function?

and why eventfb object different response res (e.g. in console log eventfb1) inside of graph.get callback function?

var graph = require('fbgraph');  var eventfb = graph.get('13216634559578/posts', {limit: 1, access_token: 34ul345kt39884p'},                 function(err, res) {                     var eventfb1 = res;                     console.log(eventfb1);                 });  console.log(eventfb1); 

thanks!

it because graph.get asynchronous request whereas javascript synchronous execution.

therefore, code outside call executes before response request


Comments

Popular posts from this blog

Combining PHP Registration and Login into one class with multiple functions in one PHP file -

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -