Your return statement is inside the anonymous function you're passing to chrome.storage.sync.get. Your getStoragex function never issues a return and so a call to it gets the result undefined.
If chrome.storage.sync.get is a synchronous function (which it seems like it might be from the name), you can do this:
function getStoragex() {
var rv;
chrome.storage.sync.get('alertsOn', function(data) {
var optionShowAlertsx = data;
console.info("This is logging ok" + optionShowAlertsx.alertsOn);
rv = optionShowAlertsx.alertsOn;
});
return rv;
}
(That bracing style is unfamiliar to me, apologies if I've messed it up.)
Edit: It looks to me as though the sync in that name doesn't have to do with the function being synchronous or asynchronous, but rather with data syncing.
If it's asynchonous, then you can't return the result from getStoragex because getStoragex returns before the result is available. In that case, you can accept a callback that you, um, call back with the result when you have it:
function getStoragex(callback) {
chrome.storage.sync.get('alertsOn', function(data) {
var optionShowAlertsx = data;
console.info("This is logging ok" + optionShowAlertsx.alertsOn);
callback(optionShowAlertsx.alertsOn);
});
}
Alternately, promises are gaining a lot of popularity at the moment. You might look into using one of those (there are several implementations available). The result will still be asynchronous if chrome.storage.sync.get is asynchronous, though.