So when running the following code, the response of the console.log(ba)
is undefined
But when I try this in the Chrome V8 Console I get the correct output I'm expecting. I'm not completely sure what is going on here.
let ba;
function Setqa() {
( async() => {
await fetch('questions.json')
.then(res => res.json())
.then(async(data) => {
ba = await data;
});
})();
}
Setqa();
console.log(ba);
The contents of the json file are the following:
"questions": [{
"questionType": "multiple",
"question": "How is the weather",
"answers": "",
"questionAnswer": ""
},
{
"questionType": "multiple",
"question": "How are you today?",
"answers": "<textarea rows='5' class='textArea'></textarea>1",
"questionAnswer": "textPurpose1"
}
]