console.log("main-1")
function foo(param){
var p = new Promise(function(resolve, reject) {
console.log("promise-1")
if (param === 1) {
resolve("1")
} else {
reject("2")
}
console.log("promise-2")
})
return p
}
console.log("main-2")
foo(1).then(function(value) {
console.log("then-1")
})
console.log("main-3")
the running result is main-1
main-2
promise-1
promise-2
main-3
then-1
Why does main-3 run after promise