When I am using the following code the output is undefined
const getData = async() => {
$.get("foo", (data) => {
return data;
})
}
(async () => {
const d = await getData();
console.log(d);
})();
http://127.0.0.1:5000/foo
site is a json file.
But If I am using the following code I get the json file.
(async () => {
const getData = await $.get( "foo", (data) => {
return data;
});
console.log(getData);
})();
Why the first one does not give the proper output?
CodePudding user response:
It seems that you forgot a return in your function
const getData = async() => {
return $.get("foo", (data) => {
return data;
})
}