Languages

Node.js - How to make anonymous async functions?

0 points
Asked by:
Dirask JS Member
3610

Is it possible to create an asynchronous function without declaring its name (anonymous function)?

For example, how can I make the following function anonymous?

const asyncFunction = async () => {
    const response = await fetch('API');
    // some code... 
}

asyncFunction();
1 answer
0 points
Answered by:
Dirask JS Member
3610

It's called Immediately Invoked Function Expression and that executes functions as soon as they are created.

(async () => {
    const response = await fetch('API');
    // some code...
})();

Check this: 

Immediately Invoked Function Expression - MDN Docs

0 comments Add comment
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join