JavaScript Answers

How to return an empty promise with JavaScript?

Spread the love

To return an empty promise with JavaScript, we can use an async function or call Promise.resolve.

For instance, we write:

const p1 = async () => {}
const p2 = () => Promise.resolve()

to create 2 functions that returns empty promises.

p1 is an async function, so it’s a function that always returns a promise.

And since it has no return value, it returns an empty promise.

p2 is a regular function that returns an empty promise by calling Promise.resolve with no arguments.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *