Sometimes, we want to return an empty promise with JavaScript.
In this article, we’ll look at how to return an empty promise with JavaScript.
How to return an empty promise with JavaScript?
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.
Conclusion
To return an empty promise with JavaScript, we can use an async function or call Promise.resolve
.