0
0
Javascriptprogramming~20 mins

Await keyword behavior in Javascript - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Await Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of async function with await
What is the output of this code snippet?
Javascript
async function test() {
  const result = await Promise.resolve('Hello');
  console.log(result);
}
test();
Aundefined
BPromise { 'Hello' }
CHello
DSyntaxError
Attempts:
2 left
💡 Hint
Remember that await unwraps the resolved value of a Promise.
Predict Output
intermediate
2:00remaining
Await with non-Promise value
What will this code output?
Javascript
async function example() {
  const val = await 42;
  console.log(val);
}
example();
APromise { 42 }
B42
Cundefined
DTypeError
Attempts:
2 left
💡 Hint
Await can be used with non-Promise values too.
Predict Output
advanced
2:00remaining
Await inside non-async function
What happens when this code runs?
Javascript
function test() {
  const result = await Promise.resolve('Done');
  console.log(result);
}
test();
APromise { 'Done' }
BDone
CReferenceError
DSyntaxError
Attempts:
2 left
💡 Hint
Await can only be used inside async functions or modules.
Predict Output
advanced
2:00remaining
Order of execution with await
What is the order of console output when this code runs?
Javascript
async function run() {
  console.log('Start');
  await new Promise(resolve => setTimeout(resolve, 0));
  console.log('End');
}
run();
console.log('After run');
AStart\nAfter run\nEnd
BStart\nEnd\nAfter run
CAfter run\nStart\nEnd
DEnd\nStart\nAfter run
Attempts:
2 left
💡 Hint
Await pauses the async function but does not block the main thread.
🧠 Conceptual
expert
2:00remaining
Await behavior with rejected Promise
What happens when this code runs?
Javascript
async function test() {
  try {
    await Promise.reject('Error occurred');
  } catch (e) {
    console.log('Caught:', e);
  }
}
test();
ACaught: Error occurred
BUncaught (in promise) Error occurred
CSyntaxError
Dundefined
Attempts:
2 left
💡 Hint
Await throws if the Promise rejects, so catch block runs.