I'm having problem with async function, in this senario, i want to return true outside async function after it run successful, but i still stuck, here is example of that
const returnSomethingIfHaveData = () => {
const someAsyncFunc = async () => {
try {
const data = await fetch('https://dummyjson.com/products/1').then(()=>true)
return data
} catch (e) {
console.log(e);
}
};
if(someAsyncFunc().then(data=>data)===true) return true
else if(someAsyncFunc().then(data=>data)===false) return false
};
console.log(returnSomethingIfHaveData()) // ==> always return nothing
Why it always false, and how to make it right? I mean it return true after it finish or i mean how to make it wait until api call done, mean how to make it return true always?