Sobes.tech
Junior — Middle

What happens if an asynchronous function finishes without an explicit return statement?

sobes.tech AI

Answer from AI

If an asynchronous function in Node.js completes without an explicit return statement, it automatically returns a Promise that resolves with the value undefined.

For example:

async function example() {
  // no return
}

example().then(result => {
  console.log(result); // undefined
});

This is important to consider if the calling code expects a specific value from the asynchronous function — the absence of return will result in the result being undefined.