var temp = function(){
return new Promise(
(resolve, reject)=>{
setTimeout(
()=>{console.log(1)}
,1000)
}
)
}
temp().then(
()=>{
console.log(2)
}
)
I'm practicing my promise.
Wait 1 second and print out 1, then print out.
Why can't I print out 1 and 2?
javascript promise
var temp = function() {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log(1);
resolve();
}, 1000)
});
}
temp().then(() => {
console.log(2)
});
resolve()
is missing.
Note: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Promise/resolve
© 2024 OneMinuteCode. All rights reserved.