You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> `Promise.all[...promises]` method wait for an array of promises to resolve. Promise.all() will reject immediately upon any of the input promises being rejected. In our case, During runPromises() function invocation, promise_3 gets rejected with the value 'Third'. The value gets logged to the console, via error handling Promise Instance Method `catch()`. As a result, 'Third' gets printed.
289
+
290
+
</p>
291
+
</details>
292
+
</li>
293
+
294
+
---
295
+
296
+
<li>
297
+
298
+
**What's the output of the following Promise operation?**
299
+
300
+
```JS
301
+
var p =newPromise((resolve, reject) => {
302
+
reject(Error('The Fails!'))
303
+
})
304
+
p.catch(error=>console.log(error.message))
305
+
p.catch(error=>console.log(error.message))
306
+
```
307
+
308
+
- A: `print error message once`
309
+
- B: `print error message twice`
310
+
- C: `Unhandled Promise Rejection warning`
311
+
- D: `process exits`
312
+
313
+
<br/>
314
+
<details>
315
+
<summary><b>Answer</b></summary>
316
+
<p>
317
+
318
+
#### Option: B
319
+
320
+
> The promise `p` gets rejected due to `reject` callback in Promise Constructor and the error message gets attached to the `.catch()` method. In this case, `.catch()` works like the DOM `.addEventListener('event', callback`) method. Both catch method will be called separately with the same arguments. Hence, the error message gets printed twice.
0 commit comments