Just like we promise something to someone for a particular thing, In JavaScript we can promise something to a user.

For ex: “I promise that I’ll fetch the data from server for you”

Now here a promise can be either fulfilled or it may not be fulfilled. correct? So here we can specify that if a promise is fulfilled, then feel grateful or if it is not fulfilled, apologise.

Okay now the concept is clear. Let’s see how that looks like if we code.

function promiser(){
return new Promise(function(resolve, reject){
const error = true; //Some HttpRequest to server
resolve(); //when promiser got data, promise is kept/resolved
console.log(“Promiser: Promise fulfilled”);
reject(); //when promiser didn’t get data, promise is broken/rejected.
console.log(“Promiser: Promise not resolved”);

promiser(); //Calling promiser

#javascript-tips #javascript #programming

Quick Understanding Of Promise in JavaScript
1.10 GEEK