I have this really simple function, which tries to lookup a value in the local storage:
function get_sectoken() {
var sectoken;
chrome.storage.local.get(null, function(obj) {
if (obj.sectoken_val) {
sectoken = obj.sectoken_val;
console.log("Security token: " + sectoken);
} else {
console.log("Security token not found!");
}
});
return sectoken;
}
If I try to assign it to a variable, I can see that console.log()
has fired up:
st = get_sectoken();
Security token: UoMjWVeEeEqxeCKpRYaMmxIGAFyofEpC
But if I check what has been assigned to this variable, I see it's undefined
:
st
undefined
What am I doing wrong?