JavaScript? How to use Promise -
JavaScript? How to use Promise
by on on other

JavaScript? How to use Promise

How to use Promise JavaScript?

Promise Chain are perfect way to handle multiple or more operation with break. Although there are good examples of using synchronous operation, async operations are also good. Imagine you have a normal function and you would want another function to run immediately that finishes one common way of doing it is to initialize that function inside the first one. That look example will look good but for some reason not expedient.

functionOne (){
functionTwo()
}
functionTwo (){
}

then

functionOne()

But with Promise we don't need to run our functions or operation inside the other. Here is a way we can do that.

new Promise((resolve, reject)=> {
resolve(functionOne())
}).then(()=> {
functionTwo()
})