Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Yes, it is possible to invoke an asynchronous function without using the await keyword.

One way to do so is by using the Promise.then() method. This method is called when the Promise is fulfilled (i.e., when the asynchronous function completes). Here is an example:

function myAsyncFunc() {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve("Hello world");
    }, 1000);
  });
}

myAsyncFunc().then((result) => {
  console.log(result);
});

In this example, myAsyncFunc() returns a Promise that resolves to "Hello world" after a timeout of 1 second. We then call the Promise.then() method on the returned Promise, which logs the result to the console.

Note that using the await keyword is generally the recommended way to handle asynchronous functions, as it provides cleaner and more readable code.