Challenge - 5 Problems
Node.js Debugging Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🔧 Debug
intermediate2:00remaining
Identify the error in this Node.js asynchronous code
What error will this Node.js code produce when run?
Node.js
async function fetchData() { const response = await fetch('https://api.example.com/data'); const data = await response.json(); return data; } fetchData().then(result => console.log(result)); console.log(data);
Attempts:
2 left
💡 Hint
Look at where the variable 'data' is used outside the async function.
✗ Incorrect
The variable data is declared inside the async function fetchData and is not accessible outside it. Trying to log data outside causes a ReferenceError.
❓ component_behavior
intermediate2:00remaining
What happens when a Node.js server callback throws an error?
Consider this Node.js HTTP server code. What will happen if the callback throws an error?
Node.js
import http from 'http'; const server = http.createServer((req, res) => { if (req.url === '/error') { throw new Error('Test error'); } res.end('Hello World'); }); server.listen(3000);
Attempts:
2 left
💡 Hint
Think about unhandled exceptions in Node.js event callbacks.
✗ Incorrect
Throwing an error inside the server callback without a try-catch causes the Node.js process to crash, stopping the server.
📝 Syntax
advanced2:00remaining
Which option correctly uses optional chaining in Node.js?
Which code snippet correctly uses optional chaining to safely access a nested property?
Attempts:
2 left
💡 Hint
Optional chaining must be used before each property that might be undefined.
✗ Incorrect
Option B safely accesses subProp only if obj and prop exist. Other options either miss optional chaining on a property or incorrectly use it on a function call.
❓ state_output
advanced2:00remaining
What is the output of this Node.js event emitter code?
What will this code print to the console?
Node.js
import EventEmitter from 'events'; const emitter = new EventEmitter(); emitter.on('start', () => { console.log('Started'); emitter.emit('process'); }); emitter.on('process', () => { console.log('Processing'); }); emitter.emit('start');
Attempts:
2 left
💡 Hint
Events can trigger other events synchronously.
✗ Incorrect
The 'start' event handler logs 'Started' and then emits 'process', which logs 'Processing'. So both lines print in order.
🧠 Conceptual
expert2:00remaining
Why is debugging asynchronous code in Node.js challenging?
Which reason best explains why debugging asynchronous Node.js code can be difficult?
Attempts:
2 left
💡 Hint
Think about how asynchronous callbacks affect the flow of execution and error tracing.
✗ Incorrect
Asynchronous callbacks may run later and out of the original call order, making stack traces harder to follow and causing confusion during debugging.