0
0
Javascriptprogramming~20 mins

JavaScript runtime overview - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
JavaScript Runtime Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of asynchronous code with setTimeout
What is the output of this JavaScript code snippet?
Javascript
console.log('Start');
setTimeout(() => console.log('Timeout'), 0);
console.log('End');
A"Timeout" "Start" "End"
B"Start" "End" "Timeout"
C"Start" "Timeout" "End"
D"End" "Start" "Timeout"
Attempts:
2 left
💡 Hint
Remember that setTimeout callbacks run after the current call stack is empty.
🧠 Conceptual
intermediate
2:00remaining
Understanding the call stack and event loop
Which statement best describes the role of the event loop in the JavaScript runtime?
AIt handles asynchronous callbacks by moving them from the callback queue to the call stack when the stack is empty.
BIt manages the execution of synchronous code only.
CIt pauses the call stack until all asynchronous operations complete.
DIt executes all asynchronous code immediately before synchronous code.
Attempts:
2 left
💡 Hint
Think about how JavaScript handles asynchronous events without blocking synchronous code.
Predict Output
advanced
2:00remaining
Output of Promise and microtasks
What will be the output of this code snippet?
Javascript
console.log('A');
Promise.resolve().then(() => console.log('B'));
console.log('C');
A"B" "A" "C"
B"A" "B" "C"
C"A" "C" "B"
D"C" "A" "B"
Attempts:
2 left
💡 Hint
Promises use microtasks which run after the current synchronous code but before setTimeout callbacks.
🔧 Debug
advanced
2:00remaining
Identify the error in this asynchronous code
What error will this code produce when run?
Javascript
setTimeout(() => {
  console.log(x);
  let x = 10;
}, 0);
ASyntaxError
Bundefined
C10
DReferenceError: Cannot access 'x' before initialization
Attempts:
2 left
💡 Hint
Consider how variable declarations with let behave inside blocks.
🚀 Application
expert
3:00remaining
Predict the output of nested asynchronous calls
What is the output order of this code?
Javascript
console.log('1');
setTimeout(() => {
  console.log('2');
  Promise.resolve().then(() => console.log('3'));
}, 0);
Promise.resolve().then(() => console.log('4'));
console.log('5');
A"1" "5" "4" "2" "3"
B"1" "2" "3" "4" "5"
C"1" "5" "2" "4" "3"
D"1" "4" "5" "2" "3"
Attempts:
2 left
💡 Hint
Remember microtasks run after synchronous code but before setTimeout callbacks. Also, microtasks inside setTimeout run after that callback.