A question about promise

topic description

let _resolve;
let promise2 = new Promise((resolve, reject) => _resolve = resolve);

promise2.then((data)=>{
    console.log(data);
})
setTimeout(()=>{
    _resolve(2000000000);
},7000)
The execution result of

code?

Why is this?

Jul.28,2021

wait 7 seconds to print 2000000000, because it takes 7 seconds for you to let it complete


Brother you mean that the assignment has no parentheses, that is, it is not executed. The real execution is in the timeout call. All successful callbacks are that the data will receive this data, and the hope from the timeout call will help you

.
Menu