0

I'm unable to assign variable from async operation using callback . .done didn't assign value to variable. Here my code :

var someGlobalVar = 0;
dbs.count('cfs_init').done(function(x) {

console.log('Total : ' + x); 
someGlobalVar = x;
}); 

console.log(someGlobalVar); // 0 
syahman
  • 35
  • 2
  • 7

1 Answers1

0

Your assignment works if you manually (or in setTimeout function) execute console.log(someGlobalVar);, after receiving done callback.

You are executing it before done callback and hence it is still 0.

Kyaw Tun
  • 12,447
  • 10
  • 56
  • 83