JavaScript promises: 4 gotchas and how to avoid them
Briefly

The article discusses advanced concepts of JavaScript promises, highlighting four potential pitfalls developers face. It emphasizes how promise handlers inherently return promises, advising against unnecessarily wrapping them. Additionally, it suggests using Promise.resolve() to standardize values that may or may not be promises, easing the handling of asynchronous code. Through practical examples, the article illustrates how to avoid common mistakes and effectively manage promise-based operations in JavaScript.
If you're returning information from a then or catch handler, it will always be wrapped in a promise, if it isn't a promise already.
If you are unsure if your incoming value is a promise already, you can simply use the static method Promise.resolve().
Promise handlers return promises; you can just return the next promise instead of wrapping it in another Promise.
Using Promise.resolve() allows you to easily work with values that may or may not be promises.
Read at InfoWorld
[
|
]