Debug fifteen async/await programs: SyntaxErrors from await outside async code, async constructors and getters, and await as a name; runtime errors from unhandled rejections, using promises as values, bad JSON and missing methods; and silent bugs from missing awaits, sequential awaits, forEach, return without await and promises used as booleans.
Question 11Easy
The code below runs without an error, but its result is wrong. Which statement correctly identifies the bug?
main.js
async function getPrice() {
return 499;
}
async function main() {
const price = getPrice();
console.log("Price:", price);
}
main();
AgetPrice() is not awaited, so price is the promise itself – write const price = await getPrice()
Basync functions cannot return numbers
Cconsole.log cannot print numbers from functions
Dmain must be awaited
Correct Answer: Option A
Node shows a fulfilled promise as Promise { 499 }. With await the line prints Price: 499.
We use Google Analytics cookies to see how LearnFrenzy is used and make it better, and Google AdSense to keep it free.
No analytics or ad cookies are set until you accept. Privacy Policy
·