110 likes | 124 Views
In this presentation on "JavaScript Promises", we introduce you to the concepts of Asynchronous programming in JavaScript and how it is achieved. A promise is an action that may complete at some point in the future and produce a value. Once the value is produced, it notifies. In this tutorial, we learn the following - <br><br>This JavaScript Certification course helps you master the JavaScript programming language in an all-inclusive training program that includes complete JavaScript fundamentals, jQuery, Ajax, and more. You will apply your skills by building a real-time chat application.<br><br>JavaScript Course Overview:<br>This training program entails the fundamentals of JavaScript, including the enumeration and elaboration of various data types in JavaScript, an explanation of loops and conditional statements in JavaScript, and an overview of the concepts of objects and variables in JavaScript.<br><br>JavaScript Certification Key Features<br>1. 100% Money Back Guarantee<br>2. 7 complete JavaScript courses<br>3. Covers Ajax, jQuery, and node.js<br>4. Build a real-time chat application<br>5. Course completion certificate<br><br>ud83dudc49Learn more at: https://bit.ly/2SDfYl<br>
E N D
Why does JavaScript use promises and what exactly is a promise? Don’t worry! I’ll help you with it. I’ll tell you why Promises were introduced and explain their functionality
Why JavaScript Promises? JavaScript is predominantly single threaded. This makes it slow and restrictive With the help of promises and other Asynchronous concepts, JavaScript can perform long network requests simultaneously without blocking the main thread
What’s in it for you? Click here to watch the video
What are JavaScript Promises? A promise is an asynchronous action that may complete at some point in the future and produce a value It notifies the user when its value is available Promises provide a robust way to wrap the result of asynchronous work, overcoming the problem of deeply nested callbacks
What are JavaScript Promises? States of Promises Pending: The underlying operation has not yet completed Fulfilled: The operation has finished, and the promise is fulfilled with a value Rejected: An error has occurred during the operation, and the promise is rejected with a reason A promise is an asynchronous action that may complete at some point in the future and produce a value It notifies the user when its value is available Promises provide a robust way to wrap the result of asynchronous work, overcoming the problem of deeply nested callbacks
What are JavaScript Promises? States of Promises Pending: The underlying operation has not yet completed Fulfilled: The operation has finished, and the promise is fulfilled with a value Rejected: An error has occurred during the operation, and the promise is rejected with a reason A Promise is said to be settled when it is either fulfilled or rejected Once a promise is settled, it becomes immutable, and its state cannot change then(callback) – Used to attach a callback when the promise is resolved/fulfilled catch(callback) – Used to attach a callback when the promise is rejected
What are JavaScript Promises? A Promise is said to be settled when it is either fulfilled or rejected Once a promise is settled, it becomes immutable, and its state cannot change then(callback) – Used to attach a callback when the promise is resolved/fulfilled catch(callback) – Used to attach a callback when the promise is rejected
What are JavaScript Promises? Return Asynchronous action .then(callback) (Fulfilled) Yes Action successful? Async. Action New Promise (pending) end No .catch(callback) (Rejected) Error handling Return
What are JavaScript Promises? Return Asynchronous action .then(callback) (Fulfilled) General Syntax: let some_action = new Promise(function(resolve, reject) { // Perform some work }) Yes Action successful? Async. Action New Promise (pending) end No .catch(callback) (Rejected) Error handling Return