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

Lists in Python -

android - can not access to progress bar in an other activity -

java - Vaadin 7 Pass Data Between Views -