Posts

Showing posts with the label Promise and Async/Await

Difference Between Promise and Async/Await :-

Image
  JavaScript is a single-threaded language, which means it can only execute one line of code at a time. Asynchronous operations, such as fetching data from a server or waiting for user input, can block the main thread of execution and make the application unresponsive. Promises Promises allow us to handle asynchronous operations in a non-blocking way. With promises, we can initiate an asynchronous operation and attach a callback function to handle the result when it becomes available. This allows the main thread of execution to continue with other tasks while the asynchronous operation is being performed in the background. Promise chaining and async/await are two approaches to handle asynchronous operations. Promise Chaining In promise chaining, we use the  then()  method to chain multiple asynchronous operations. This is useful when we have multiple asynchronous operations that need to be performed in a specific order. Async - Await Async/await allows us to write asynchr...