Output: async function returning a promise vs returning a plain value, raced against a then chain
HardP3Output
What does this code print? One of the async functions returns a promise instead of a plain value.
1async function plain() {2 return 'plain';3}4async function viaPromise() {5 return Promise.resolve('promise');6}78plain().then(console.log);9viaPromise().then(console.log);1011Promise.resolve()12 .then(() => console.log('t1'))13 .then(() => console.log('t2'))14 .then(() => console.log('t3'))15 .then(() => console.log('t4'));
Saved automatically
One line per console.log. Arrays as [1, 2, 3], objects as { a: 1 }, an uncaught error as Uncaught TypeError: message (Chrome and Node wording).
Hints
Saved automatically