I have lot of confusion in promise. It\'s a synchronous or asynchronous ?
return new Promise (function(resolved,reject){
//sync or async?
});
>
When you create a promise and pass a call back to it that callback is gonna executed immediately (sync)
const promise= new Promise(function(resolve, reject) {
//doing some logic it gonna be executed synchronously
console.log("result");
})
console.log("global log")
But when you resolve it by .then() method it will act in asynchronous way so for example :
const promise = new Promise(function(resolve, reject) {
//doing some logic it gonna be executed synchronously
resolve("fullfiled")
})
promise.then(v => {
console.log(v)
})
console.log("global log")