Quiz 131 - Async await with try catch Javascript

  Рет қаралды 158

Code Gyaan

Code Gyaan

3 ай бұрын

In the provided code, there are two asynchronous functions a() and b(), and a function start() which invokes them sequentially. Let's analyze each function:
a():
- It uses await with Promise.reject(1), which immediately rejects the promise with the value 1.
- Since await is used, the rejection is caught by the try...catch block.
- However, Promise.reject(1) immediately throws an error, so the code inside the try block doesn't execute, and it goes directly to the catch block.
- Inside the catch block, it logs the error (1) to the console.
b():
- It returns a promise directly created with Promise.reject(2).
- There is no await in this function, so the rejection is not caught by any try...catch block within the function.
- Therefore, the rejection propagates to the caller of b(). start():
- It sequentially awaits the execution of functions a() and b().
- Now, when you call start(), here's what happens:
start():
- a() is called first, and it logs 1 to the console.
- Then b() is called, which throws an uncaught promise rejection with the value 2.

Пікірлер
Implement curry function in Javascript
2:13
Code Gyaan
Рет қаралды 178
Google Data Center 360° Tour
8:29
Google Cloud Tech
Рет қаралды 5 МЛН
Inside Out Babies (Inside Out Animation)
00:21
FASH
Рет қаралды 18 МЛН
Jumping off balcony pulls her tooth! 🫣🦷
01:00
Justin Flom
Рет қаралды 20 МЛН
What it feels like cleaning up after a toddler.
00:40
Daniel LaBelle
Рет қаралды 84 МЛН
Go Hindi | Can Golang multiply strings like Python can?
4:54
Async JS Crash Course - Callbacks, Promises, Async Await
24:31
Traversy Media
Рет қаралды 1,4 МЛН
Responsive Flexbox Layout in 2 Minutes
2:41
SolarDev
Рет қаралды 30 М.
10 JavaScript Interview Questions You HAVE TO KNOW
13:41
James Q Quick
Рет қаралды 51 М.
5 JavaScript Concepts You HAVE TO KNOW
9:38
James Q Quick
Рет қаралды 1,4 МЛН
Write Solid Code with Branded Types in TypeScript 🛡️
17:50
TypeScript TV with Benny
Рет қаралды 571
JavaScript Visualized - Promise Execution
8:42
Lydia Hallie
Рет қаралды 136 М.
Inside Out Babies (Inside Out Animation)
00:21
FASH
Рет қаралды 18 МЛН