resolve vs return promise js
In simple terms, inside a then handler function:
A) When x is a value (number, string, etc):
- return x is equivalent to return Promise.resolve(x)
- throw x is equivalent to return Promise.reject(x)
B) When x is a Promise that is already settled (not
pending anymore):
- return x is equivalent to return Promise.resolve(x),
if the Promise was already resolved.
- return x is equivalent to return Promise.reject(x),
if the Promise was already rejected.
C) When x is a Promise that is pending:
- return x will return a pending Promise, and it will
be evaluated on the subsequent then.
Read more on this topic on the Promise.prototype.then() docs.
Also in JavaScript:
- bullmq
- HashLocationStrategy
- how to empty table after closing modal using jquery
- use .map to count length of each element in an array
- javascript string into substrings of length
- javascript are arrays equal
- how to send a message to a discord server using a bot
- VS javascript can't import file 3 folders up
- js initialize 2d array
- how to compare elements in an array
- js draggable
- react native function
- reset value object js
- extract string from text file javascript
- find and replace value in array of objects javascript
- angular pipe to capitalize first letter
- dayjs invalid date
- declare function javascript
- js promise examples
- object javascript match by property value
- swagger editor
- Set Custom User Agent react
- add javascript
- we need a server for server side rendering of angular