Challenge - 5 Problems
JavaScript Console Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of console.log with variable scope
What will be printed in the browser console after running this code snippet?
Javascript
let x = 10; function test() { let x = 20; console.log(x); } test(); console.log(x);
Attempts:
2 left
💡 Hint
Remember that variables declared inside a function have local scope.
✗ Incorrect
Inside the function, x is 20 because of local declaration. Outside, x remains 10.
❓ Predict Output
intermediate2:00remaining
Console output of asynchronous code
What is the order of outputs in the browser console after running this code?
Javascript
console.log('Start'); setTimeout(() => console.log('Timeout'), 0); console.log('End');
Attempts:
2 left
💡 Hint
setTimeout callbacks run after the current call stack is empty.
✗ Incorrect
Synchronous logs run first, then the setTimeout callback runs.
🔧 Debug
advanced2:00remaining
Identify the error in console usage
Which option will cause an error when run in the browser console?
Javascript
console.log('Hello');
Attempts:
2 left
💡 Hint
Check for missing parentheses or syntax errors.
✗ Incorrect
Option A is missing a closing parenthesis, causing SyntaxError.
🧠 Conceptual
advanced2:00remaining
Console methods for different outputs
Which console method prints a message only if a condition is false?
Attempts:
2 left
💡 Hint
This method is used for debugging assumptions.
✗ Incorrect
console.assert() prints message only if the first argument is false.
❓ Predict Output
expert2:00remaining
Output of console.log with object mutation
What will be the output in the console after running this code?
Javascript
const obj = {a: 1}; console.log(obj); obj.a = 2; console.log(obj);
Attempts:
2 left
💡 Hint
Objects logged show their state at the time of logging.
✗ Incorrect
First log shows {a:1}, after mutation second log shows {a:2}.