Important JavaScript Concept for Interviews - 'Promise'
๐ Promise in JS
๐ Asynchronous Operations
๐ States of Promise
๐ Promise Consumers
A Thread ๐งต๐
๐ Promise in JS
๐ Asynchronous Operations
๐ States of Promise
๐ Promise Consumers
A Thread ๐งต๐
๐ Promise
A Promise is an object that represents the eventual completion or failure of an asynchronous operation, and its resulting value.
As JS is single-threaded, scripts run one after another. Hence, there is an abundance of asynchronous jobs.
A Promise is an object that represents the eventual completion or failure of an asynchronous operation, and its resulting value.
As JS is single-threaded, scripts run one after another. Hence, there is an abundance of asynchronous jobs.
๐ Asynchronous Operations
The single-threaded functionality of JS stops you from performing long operations.
Using asynchronous JavaScript (such as callbacks, promises, and async/await), you can perform long network requests without blocking the main thread.
The single-threaded functionality of JS stops you from performing long operations.
Using asynchronous JavaScript (such as callbacks, promises, and async/await), you can perform long network requests without blocking the main thread.
๐ Promises prove to be the ideal choice for handling asynchronous operations in JavaScript.
They can handle multiple asynchronous operations easily and provide better error handling
Benefits - Code Readability, handling of asynchronous operations, Error Handling
They can handle multiple asynchronous operations easily and provide better error handling
Benefits - Code Readability, handling of asynchronous operations, Error Handling
๐ Parameters
Promise takes the Callback function as its parameter. Similarly, callback takes two parameters -
๐ Resolve
๐ Reject
When the operation goes as expected -> Resolve
If there is something wrong -> Reject
Promise takes the Callback function as its parameter. Similarly, callback takes two parameters -
๐ Resolve
๐ Reject
When the operation goes as expected -> Resolve
If there is something wrong -> Reject
That's a wrap!
If you enjoyed this thread:
1. Follow me @SushrutKM for more of these
2. RT the tweet below to share this thread with your audience
If you enjoyed this thread:
1. Follow me @SushrutKM for more of these
2. RT the tweet below to share this thread with your audience
Loading suggestions...