Why the plugin chrome returns undefined?

function show(){
 return chrome.storage.sync.get('AWSAccessKeyId',function(result){
 return result.AWSAccessKeyId;
});
}

var item = show();
alert(item)


returns undefined
July 8th 19 at 16:28
1 answer
July 8th 19 at 16:30
Solution
getAWSAccessKeyId function() {
 return new Promise(function (resolve, reject) {
 chrome.storage.sync.get('AWSAccessKeyId', function (result) {
resolve(result.AWSAccessKeyId);
});
});
}

getAWSAccessKeyId.then(alert);


getAWSAccessKeyId function(cb){
 chrome.storage.sync.get('AWSAccessKeyId', function () {
cb(result.AWSAccessKeyId);
});
}

getAWSAccessKeyId(function(AWSAccessKeyId){
alert(AWSAccessKeyId);
});


Async function ...blah-blah-blah... at the time the return result is not yet known ...blah-blah-blah... use colbecki or promises ...blah-blah-blah... read learn.javascript.ru...

PS Today seems to be the first to ask a question about async in js
P. P. S. does anyone have a link to reference the answer to this question? Throw in comments to same not to write every time.
and you don't know whether it is possible to set the time of your life? - jabari_Bayer91 commented on July 8th 19 at 16:33
https://developer.chrome.com/extensions/storage - aniya commented on July 8th 19 at 16:36

Find more questions by tags JavaScript