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
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
.