I have been trying to read up on how asynchronicity works and what promises are, but still not grasping the concept properly.
I understand that asynchronous function returns a promise but at the same time it can return content from an api in my case.
let username = list_scores[i].score.username;
///Await Hiscores fetches json from api.
///Hiscores connects to third party api and fetches data dependant on (name)
async function getUserAsync() {
async function getHS (name) {
var response = await Hiscores.fetch(name).catch(console.error)
var result = JSON.stringify(response);
// var resultparse = JSON.parse(result)
return result;
}
return getHS(username).then(result => JSON.parse(result)).catch(console.error);
}
let hs = getUserAsync().then(console.log)
In the above example json fetched in var response shows up in the console as intended but when I change it to try and make it return the same log as a variable
let hs = getUserAsync().then(res => {return res;}).catch(console.error)
console.log(hs)
It returns
Promise { <pending> }
Kind of at a loss here , been googling for few days now....