I have some JavaScript code like this:
var account_name;
fetch('[URL]')
.then(res => res.json())
.then((out) => {
account_name = out.account_name;
}).catch(err => console.error(err));
console.log(account_name);
account_name_field.innerHTML = account_name;
But when I run it, the console says:
User.html:192 Uncaught ReferenceError: account_name is not defined
at update_from_config (User.html:194)
at onload (User.html:76)
I've tried multiple methods to declare a global variable, but none of them seem to work. Any help would be much appreciated.