What is the output of the following JavaScript code?
1Times asked
Apr 2026Last seen
Apr 2026First seen
💡 Model Answer
The code will throw a SyntaxError. The function hello is defined without the async keyword, yet it contains an await expression. In JavaScript, await can only be used inside an async function. Therefore, when the interpreter reaches await sayAfter2Seconds("Hello World"), it throws an error: "SyntaxError: Unexpected identifier 'await'". If hello were declared as async function hello(), the code would wait 2 seconds and then log "Hello World" to the console.
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers — invisible to screen sharing.
Get Assisting AI — Starts at ₹500