javascript - Why is variable inside callback function undefined outside of it? -
this question has answer here:
- how return response asynchronous call? 25 answers
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
Post a Comment