Callback Returns Undefined With Chrome.storage.sync.get
Answer : The chrome.storage API is asynchronous - it doesn't return it directly, rather passing it as an argument to the callback function. The function call itself always returns undefined . This is often used to allow other methods to run without having to wait until something responds or completes - an example of this is setTimeout (only difference is that it returns a timer value, not undefined ). For example, take this: setTimeout(function () { alert(1); }, 10000); alert(0); Because setTimeout is asynchronous, it will not stop all code until the entire function completes, rather returning initially, only calling a function when it is completed later on - this is why 0 comes up before 1. For this reason, you cannot simply do something like: // "foo" will always be undefined var foo = asyncBar(function (e) { return e; }); Generally, you should put what you want to do in your callback (the function that is called when the asynchronous function i...