I was wondering how promises are resolved in javascript. If anyone could explain how promises in the code below are processed. I understand that js compiler maintains a separate queue for promises.
const promisePrint = (n) =>{
return new Promise(res=>{
console.log(n, 'inside')
res(n)
})
}
(async()=>{
console.log(await promisePrint(33), 'outside')
console.log(await Promise.resolve(10))
})()
Promise.resolve()
.then(()=>console.log(1))
.then(()=>console.log(2))
.then(()=>console.log(3))
Output:
33 'inside'
1
2
33 'outside'
3
10
some resources referred: https://www.youtube.com/playlist?list=PLillGF-Rfqbars4vKNtpcWVDUpVOVTlgB
And why is 33 'outside'
taking so long to be resolved?