0

I have this code below:

function searchQuery() {
  var r = 'toReplace';
  chrome.storage.sync.get(['search_query'], function(result) {
    console.log(result.search_query);
    r = result.search_query;
  });
  return r;
}

I console.log this function somewhere else, and the console.log inside the sync.get function outputs the right thing, but the function itself is "toReplace." Why is this?

1
  • 1
    storage.sync doesn't appear to be synchronous. The sync stands for "synchronize" Commented Jun 14, 2019 at 0:09

1 Answer 1

2

As @Phil said, the call is most likely asynchronous. I'd recommend looking at using the async & await syntax.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.