0
0
Javascriptprogramming~20 mins

JavaScript execution flow - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
JavaScript Execution Flow Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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');
A"Start" "Timeout" "End"
B"End" "Start" "Timeout"
C"Start" "End" "Timeout"
D"Timeout" "Start" "End"
Attempts:
2 left
💡 Hint
Remember that setTimeout callbacks run after the current call stack is empty.
Predict Output
intermediate
2:00remaining
Variable hoisting with var
What will be the output of this code?
Javascript
console.log(x);
var x = 5;
console.log(x);
Aundefined undefined
BReferenceError 5
C5 5
Dundefined 5
Attempts:
2 left
💡 Hint
Variables declared with var are hoisted but not initialized.
Predict Output
advanced
2: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');
A"C" "A" "B"
B"A" "C" "B"
C"B" "A" "C"
D"A" "B" "C"
Attempts:
2 left
💡 Hint
Promises callbacks run after the current synchronous code but before setTimeout.
Predict Output
advanced
2: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');
A"1" "3" "2"
B"1" "2" "3"
C"3" "1" "2"
D"3" "2" "1"
Attempts:
2 left
💡 Hint
Await pauses the async function after the current synchronous code.
🧠 Conceptual
expert
2: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));
A"Done123"
B"123Done"
CTypeError
DRangeError
Attempts:
2 left
💡 Hint
Think about how the recursion returns and concatenates strings.