0

i try to return variable from variable from function, but it returns as undefined.

function getStorage(callback) {
    chrome.storage.sync.get('d', function(items) {
        callback(items);
    })
}
var itemsdm = 1;
console.log(itemsdm);
var itemsdm = getStorage(function(items) {
    var itemsdm = ' 0 ';
    for (var prop in items) {
        var itemsdm = itemsdm + items[prop];
    }
    console.log(itemsdm);
    return itemsdm;
});
console.log(itemsdm);

this gives me

1
undefined
0 ываыав
cvts32
  • 1
  • 1
  • `getStorage` does not return anything – Igor Apr 12 '17 at 14:31
  • Where do you think your callback is *returning to*? It's returning to `callback(items)`, which then doesn't do anything with the return value. – deceze Apr 12 '17 at 14:32

0 Answers0