I run this code on Nodejs and I expect that got an error but it worked!
If I set 2500 ms to setTimeout
I got an error and it’s normal.
Is there anybody here to explain it for me?
And why I see IIFE
log first?
I run this code on browser and got error as I expected.
const data = [{}]
const myPromise = new Promise((resolve, reject) => {
setTimeout(() => {
resolve([1,2,3,4]);
}, 3000);
});
console.log('hiiii');
setTimeout(() => {
data[0].map(e => console.log('to ',e))
}, 2999);
(async() => {
data[0] = await myPromise
data[0].map(e => console.log('iife ',e))
}
)()
console.log('byeeeee')
The below code is what I see on my console
hiiii
byeeeee
iife 1
iife 2
iife 3
iife 4
to 1
to 2
to 3
to 4