I am creating a chrome extension and to my surprise my content script is acting very odd. I have defined a global variable keyword but when it goes through the function that gives it it's value, the value expires when the function ends. I've spent hours troubleshooting and can't seem to find the problem.
var keyword;
chrome.extension.sendMessage({localStorage: "yo"}, function(response) {
var localStorage = response.localStorage;
keyword = localStorage["keyword"];
console.log(keyword);
});
console.log(keyword);
The log within the function returns my desired value, but the log after the function returns undefined, even though as far as I can tell, it should also return the value that was given to it within the function. I did not declare it within the function, so why does it's value expire after the function?