'async request via jquery $.get()

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?



Solution 1:[1]

It seems that you forgot a return in your function

const getData = async() => {
    return $.get("foo", (data) => {
        return data;
    })
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 R4ncid