Menu

Post image 1
Post image 2
Post image 3
1 / 3
0

Promises - JavaScript

DEV Community·Sivakumar Mathiyalagan·25 days ago
#RvppLl0u
Reading 0:00
15s threshold

what is promises in Javascript? JavaScript is synchronous by default, which means code executes in a linear, line-by-line manner. Each statement waits for the previous statement to finish before executing. However, some operations like: API calls Database queries File reading Timers (setTimeout) take time to complete. If JavaScript waited for these operations synchronously, the entire program would pause and become slow or unresponsive. To avoid blocking execution, JavaScript supports asynchronous programming. A Promise is an object that represents the eventual completion or failure of an asynchronous operation. Promises allow JavaScript to continue executing other code while waiting for long-running tasks to finish. Promises have three states: Pending = operation is still running Resolved = operation completed successfully Rejected = operation failed Why Promises? Callback functions also help perform asynchronous operations in JavaScript.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More