I have a async function which returns a promise. I'm confused to how I access the Promise value. I came across .then()
. It works with .then()
, but I want to make the promise value global. Which isn't possible if i use .then()
.
Here is my code:
async function getUser() {
try {
response = await axios.post('/',data);
}
catch (error) {
console.error(error);
}
return response.data;
}
var global = getUser();
console.log(global);
This code here returns a promise like so:
I'm wondering how can I access the Promise value (which we can see in the image) and make it global? I'm new to JavaScript unable to wrap my head around async functions.