Whenever "resolve ()" is called that completes the promise.
Also JavaScript function calls aren't blocking, meaning when you do .then on something, then another call afterwards, the second call will be executed first, then the first one. Similar idea with setTimeout etc
Here
new Promise(resolve1 => {
console.log(1)
resolve1()
})
.then(() => {
console.log(2)
})
.then(() => {
console.log(3)
})
resolve()
You first declare a new Promise, which inherently doesn't console log anything (except 1)' the logging for that one only happens in the .then calls, which, as mentioned, are executed after (some) regular function call that follows then
You are then following it with the main resolve, which prints 4. In the meantime, though, console.log takes time to operate, so even though the 2 was console logged, but it didn't have enough time to log 3 before 4, which is not dependant on waiting on the promise chain, was printed
Questions?