In this session, you learned about:
- JavaScript being a single-threaded language; yet the way it showcases the asynchronous behavior.
- Callbacks - the functions which are to be called when some predefined action is completed and when there are multiple levels of callbacks inside callbacks, the triangular shape that is formed is known as the callback hell, which makes the code hard to read, maintain, and debug.
- Promises, which is the new way of writing the asynchronous functions and are useful for converting the callback hells into much more readable and manageable code. They have two properties:
- state: Initially, when the promise is defined, its state is pending. The state changes to fulfilled / rejected once the producing code produces some result.
- result - Initially, when the promise is defined, the result is initialized to undefined. Once the producing code finishes its execution, the result is set to the output of this code.
- async and await, which are the keywords introduced in ES8 to write asynchronous functions in JavaScript. They are even better way of writing code as compared to callbacks and promises.