function delay(a) {
setTimeout(() => {
console.log(a);
}, 1000);
}
function prompt(a) {
console.log(a);
}
var temp = function() {
return new Promise((resolve) => {
delay('first');
resolve();
});
};
temp().then(() => {
prompt('second');
});
I want to print it out in the order of first and second.
The output starts from the second.
Can we print it out in first second order without modifying the delay() and
promt()
functions?
function delay(a, resolve) {
setTimeout(() => {
console.log(a);
resolve();
}, 1000);
}
function prompt(a) {
console.log(a);
}
var temp = function() {
return new Promise((resolve) => {
delay('first', resolve);
});
};
temp().then(() => {
prompt('second');
});
© 2024 OneMinuteCode. All rights reserved.