Learning how to use JavaScript Promises, Constructing a Promise Object, JavaScript Promise Example

This JavaScript programming lesson is on Learning how to use JavaScript Promises, Constructing a Promise Object, and JavaScript Promise Example. We learned what JavaScript Promises are last video, but in this lesson, we see how to construct a promise object in JavaScript. We learn that the 3 most important keywords are “new Promise()”, “resolve”, and “reject”. In order to understand JavaScript functions, it is important to understand that a promise has 3 states. We also learned it last lesson, but the 3 states are “pending” “fulfilled”, and “rejected”. We specify what should happen if the promise is resolved, and what to do if a promise is rejected. In a real setting we would create a promise, and it might be for a query in a database, and if the promise is resolved, it might return some data from the DB, and if some error was to arise, the promise may be rejected. Learning how to use JavaScript promises requires practice. Make sure to practice using JavaScript promises and look up more examples to truly understand how promises work in JavaScript. Constructing promises in JavaScript is a key step on your JavaScript programming journey! Make sure to understand how promises work in JavaScript, before moving on!