const myPromise = Promise.resolve(Promise.resolve("Promise!"));
function funcOne() {
myPromise.then(res => res).then(res => console.log(res));
setTimeout(() => console.log("Timeout!"), 0);
console.log("Last line!");
}
async function funcTwo() {
const res = await myPromise;
console.log(await res);
setTimeout(() => console.log("Timeout!"), 0);
console.log("Last line!");
}
funcOne();
funcTwo();
VM54:6 Last line!
VM54:4 Promise!
VM54:11 Promise!
VM54:13 Last line!
Promise {<fulfilled>: undefined}
VM54:5 Timeout!
VM54:12 Timeout!
const myPromise = Promise.resolve();
function funcOne() {
myPromise.then(res => res).then(res => console.log(res+'1'));
setTimeout(() => console.log("Timeout!"+'2'), 0);
console.log("Last line!"+'3');
}
async function funcTwo() {
const res = await myPromise;
console.log(await res +'4');
setTimeout(() => console.log("Timeout!"+'5'), 0);
console.log("Last line!"+'6');
}
funcOne();
funcTwo();
VM562:6 Last line!3
VM562:4 undefined1
VM562:11 undefined4
VM562:13 Last line!6
Promise {<fulfilled>: undefined}
VM562:5 Timeout!2
VM562:12 Timeout!5
const myPromise = Promise.resolve('1212');
function funcOne() {
myPromise.then(res => res).then(res => console.log(res+'1'));
setTimeout(() => console.log("Timeout!"+'2'), 0);
console.log("Last line!"+'3');
}
async function funcTwo() {
const res = await myPromise;
console.log(await res +'4');
setTimeout(() => console.log("Timeout!"+'5'), 0);
console.log("Last line!"+'6');
}
funcOne();
funcTwo();
VM734:6 Last line!3
VM734:4 12121
VM734:11 12124
VM734:13 Last line!6
Promise {<fulfilled>: undefined}
VM734:5 Timeout!2
VM734:12 Timeout!5
const myPromise = Promise.resolve(Promise.resolve('1212'));
function funcOne() {
myPromise.then(res => res).then(res => console.log(res+'1'));
setTimeout(() => console.log("Timeout!"+'2'), 0);
console.log("Last line!"+'3');
}
async function funcTwo() {
const res = await myPromise;
console.log(await res +'4');
setTimeout(() => console.log("Timeout!"+'5'), 0);
console.log("Last line!"+'6');
}
funcOne();
funcTwo();
VM809:6 Last line!3
VM809:4 12121
VM809:11 12124
VM809:13 Last line!6
Promise {<fulfilled>: undefined}
VM809:5 Timeout!2
VM809:12 Timeout!5
const myPromise = Promise.resolve(Promise.resolve('1212'));
function funcOne() {
myPromise.then(res => console.log(res+'1'));
setTimeout(() => console.log("Timeout!"+'2'), 0);
console.log("Last line!"+'3');
}
async function funcTwo() {
const res = await myPromise;
console.log(await res +'4');
setTimeout(() => console.log("Timeout!"+'5'), 0);
console.log("Last line!"+'6');
}
funcOne();
funcTwo();
VM1178:6 Last line!3
VM1178:4 12121
VM1178:11 12124
VM1178:13 Last line!6
Promise {<fulfilled>: undefined}
VM1178:5 Timeout!2
VM1178:12 Timeout!