Challenge - 5 Problems
JavaScript Execution Flow Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Understanding event loop with setTimeout
What will be the output of the following code snippet?
Javascript
console.log('Start'); setTimeout(() => console.log('Timeout'), 0); console.log('End');
Attempts:
2 left
💡 Hint
Remember that setTimeout callbacks run after the current call stack is empty.
✗ Incorrect
The synchronous console.log statements run first, printing "Start" then "End". The setTimeout callback runs last, printing "Timeout".
❓ Predict Output
intermediate2:00remaining
Variable hoisting with var
What will be the output of this code?
Javascript
console.log(x); var x = 5; console.log(x);
Attempts:
2 left
💡 Hint
Variables declared with var are hoisted but not initialized.
✗ Incorrect
The declaration of x is hoisted, so the first console.log prints undefined. Then x is assigned 5, so the second console.log prints 5.
❓ Predict Output
advanced2:00remaining
Promise execution order
What is the output order of this code?
Javascript
console.log('A'); Promise.resolve().then(() => console.log('B')); console.log('C');
Attempts:
2 left
💡 Hint
Promises callbacks run after the current synchronous code but before setTimeout.
✗ Incorrect
"A" and "C" are logged synchronously. The Promise callback logs "B" after the synchronous code.
❓ Predict Output
advanced2:00remaining
Async function execution flow
What will this code print?
Javascript
async function f() { console.log('1'); await null; console.log('2'); } f(); console.log('3');
Attempts:
2 left
💡 Hint
Await pauses the async function after the current synchronous code.
✗ Incorrect
"1" is logged immediately. Then the function pauses at await. "3" logs next. Finally, "2" logs after the await.
🧠 Conceptual
expert2:00remaining
Call stack and recursion depth
Consider this recursive function. What will happen when calling recurse(3)?
Javascript
function recurse(n) { if (n === 0) return 'Done'; return recurse(n - 1) + n; } console.log(recurse(3));
Attempts:
2 left
💡 Hint
Think about how the recursion returns and concatenates strings.
✗ Incorrect
The base case returns "Done". Then each recursive call adds the current number to the string, resulting in "Done123".