Make your promise…
1. Callback hell
There are instances when we make a callback inside of a callback (called nested callbacks). It causes issues in code readability and understanding.
2. Difficulty in handling errors
When an asynchronous function or an asynchronously invoked callback throws an exception, there is no way for that exception to propagate back to the initiator of the asynchronous operation. It breaks the exception handling.
So, the simplest solution is using our lovely Promises.
A Promise is an object built on callbacks, which represents the result of an asynchronous computation. The result may or may not be ready. Promise works asynchronously only. There is no way of getting the value through synchronous calls. You can only ask the Promise to call a callback function when the value is ready.
Promises provide solutions for nested callbacks through re-expressing the nested callbacks in the form of a Promise chain. And through Promise, we can handle the errors in the proper way by handling them in the Promise chain.
A promise can be “kept” or “broken”.
There is another state there as well, that is “pending”. When a Promise is in a state where it’s neither been fulfilled nor rejected, it is pending. A Promise is settled once it is fulfilled or rejected.
Who else loves to write side-effects-free functions? I think we, as programmers, all do. Today, in this story, I will walk you through the basic principles of functional programming that will make your coding life easier.
Formatting code consistently is a pain, especially when working on a team. The beauty of modern-day web development is that the tooling has gotten so much better! In this article, we will look at setting up Prettier to automatically format your code in Visual Studio Code.