Member-only story

Promises in javascript. Lets understand them

krishankant singhal
2 min readApr 18, 2020

--

Promises in javascript is kind of promises in real life. you promise to someone that you will do something in future or now. and there will be 2 outcome of that promise. Either promise will be fulfilled or promise will not be fulfilled.

Same behaviour is exhibited in javascript as well.

Let’s understand this using an conversation between mom and child .

1)Son Promises to his Mother , Mother i Promise i will clean my house.

So son is telling to do some work which will be done now or in future. but is not completed. so work is pending state.

2) Now Son fulfill his promise and clean the room, Promise is fulfilled he goes to play.

3) Son does not fulfill his promise and does not clean the room, and goes for laundry.

So basically promise is an action which will be performed in future and guaranteed to return with result(pass or failure whatever).

So Promise will have three state, pending, resolved or rejected.

How to create a promise in javascript

var cleanedtheroom = false
var…

--

--

krishankant singhal
krishankant singhal

Written by krishankant singhal

Angular,Vuejs,Android,Java,Git developer. i am nerd who want to learn new technologies, goes in depth.

No responses yet