Mark As Completed Discussion

One Pager Cheat Sheet

  • If you understand the differences between blocking and non-blocking operations and how they relate to asynchronous 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 either fulfilled, rejected, or pending.
  • 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 Promises, allowing us to suspend the resolution of an asynchronous function explicitly, without needing to reason about multiple states.
  • The async/await concept allows promises 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 an async function is suspended until its Promise results in a resolved value.
  • Asynchronous function hello() does not contain an await keyword, and the code will throw a ReferenceError that will be caught within the try...catch block, returning the value "Boo! You have a ReferenceError: abc is not defined", and logged out to the console through the .catch() method.