A have a code for a simple api request, that should yield some data and it does! But it returns this data only in .then() block. Any attempt to save it in a variable lends in undefined. Where did I go wrong?
const link = "https://semalt.net/dev/api/v1/example/test/";
let queryData;
async function getData(link) {
try {
const result = await fetch(link);
const data = await result.json();
return data.result;
} catch {
alert(error);
}
}
getData(link).then((array) => {
queryData = array;
console.log(queryData);
});