My checkStorage function gets the correct value based on a key I pass to it. However when I want to return this value and use it in the main code I get 'undefined'
I also get the main alert BEFORE I get the on from within the function... Why is that?
What am I doing wrong here please? Thanks
chrome.storage.sync.set({'myKey': 'myValue'});
function checkStorage(key){
chrome.storage.sync.get(key, function(result) {
alert('function: myValue is '+ result[key]) // this works, alerts myValue
return result[key]
});
}
alert('main: myValue is ' + checkStorage('myKey')) ; // does not work, alerts undefined