sorry for the basic question. I was trying using fetch to get data from api and want to store that response into a javascript variable but its not working as I have expected My code-
async function fun() {
var a = "initial";
fetch('https://jsonplaceholder.typicode.com/todos/1')
.then(res => res.json())
.then(data => {
a = data;
console.log(a);
})
await console.log("Response => ", a);
}
Output - Response => initial
What is the correct way of doing this.