In this JavaScript Promise tutorial you will learn how to use "Promise" in JavaScript Code
JavaScript Promise is the new features of advanced JavaScript (ES6), specially used when you want to write async JavaScript function in Node application development, so to learn this feature you may need to have Visual Studio Code or something similar editor.
A promise is a single object value, which will indicate the state of any JavaScript call, there can be three different possibilities.
JavaScript Promises are used to manage multiple asynchronous operations where callbacks can call another function.
Here is an example of javascript function that will returns promise, which will resolve after a specified time duration.
const wait = time => new Promise((resolve) => setTimeout(resolve, time)); wait(5000).then(() => console.log('Hello World!'));
Here is another promise example.
var promise = new Promise(function(resolve, reject) { const a = "JavaScript"; const c = "WebTrainingRoom"; if(a === c) { resolve(); } else { reject(); } }); promise. then(function () { console.log('Success, Well Done'); }). catch(function () { console.log('There are some error'); });