One Pager Cheat Sheet
- If you understand the differences between
blocking
andnon-blocking
operations and how they relate toasynchronous
operations in web development, you can easily master working with these concepts. - In asynchronous execution, lines of code don't have to wait for each other to complete before being executed, as demonstrated using the
setTimeout()
method. - Despite being a common anti-pattern in JavaScript,
Callback Hell
can be avoided by taking a closer look at our code to prevent the pyramid of doom from growing. - Promises
solve the problem of callback hell
by providing a simpler syntax to chain asynchronous operations and better error handling. - You can create and use a
Promise
during asynchronous programming to represent a state that can be eitherfulfilled
,rejected
, orpending
. - The output of a
Promise
can be accessed using three methods:.then()
,.catch()
and.finally()
,.then()
being used to access a successful response and.catch()
used to access an error response. - The two key methods for retrieving the value from a
Promise
are.then()
and.catch()
, which are used to get a value or an error respectively. - With async/await, we have a simpler approach to writing
Promise
s, allowing us to suspend the resolution of an asynchronous function explicitly, without needing to reason about multiple states. - The
async/await
concept allowspromises
to be suspended while the code outside the function continues to execute, finally providing the expected output once the promise is resolved. - By using the
await
keyword, execution of anasync function
is suspended until itsPromise
results in aresolved value
. - Asynchronous function
hello()
does not contain anawait
keyword, and the code willthrow a ReferenceError
that will be caught within thetry...catch
block, returning the value"Boo! You have a ReferenceError: abc is not defined"
, and logged out to the console through the.catch()
method.