About promise and setTimeout

var p1 = new Promise(function (resolve, reject) {
    setTimeout(function(){
        resolve(1);
        console.log("p1");
    },5000)
});

var p2 = new Promise(function (resolve, reject) {
      resolve(p1);
}).then(function(data){
    console.log(data);
    console.log("p2");
})

Why does the result be p1percent = > 1percent = > p2 instead of 1percent = > p2percent = > p1?

Apr.05,2021

p2 is determined by p1. After 5000ms, pi is changed to resolved, p2 is directly changed to resolved, and then then is executed

.
Menu