Challenge - 5 Problems
Node.js Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:00remaining
Output of a simple Node.js script
What is the output when running this Node.js script?
Javascript
console.log('Hello from Node.js!');
Attempts:
2 left
💡 Hint
Look at what console.log prints to the terminal.
✗ Incorrect
console.log prints the string to the console, so the output is exactly the string inside the quotes.
❓ Predict Output
intermediate1:30remaining
Understanding asynchronous behavior in Node.js
What will be the output order when running this Node.js code?
Javascript
console.log('Start'); setTimeout(() => console.log('Timeout'), 0); console.log('End');
Attempts:
2 left
💡 Hint
setTimeout with 0 delay runs after the current call stack is empty.
✗ Incorrect
The synchronous logs run first: 'Start' then 'End'. The setTimeout callback runs last.
❓ Predict Output
advanced1:30remaining
Output of a Node.js script using process.argv
What will be the output if you run this script with: node script.js hello world?
Javascript
console.log(process.argv.slice(2));
Attempts:
2 left
💡 Hint
process.argv contains command line arguments; slice(2) skips the first two.
✗ Incorrect
process.argv is an array of command line arguments. The first two are node executable and script path.
❓ Predict Output
advanced1:30remaining
Error type when requiring a non-existent module
What error will Node.js throw when running this code?
Javascript
require('nonexistent-module');
Attempts:
2 left
💡 Hint
Node.js throws an error if a required module is missing.
✗ Incorrect
The error message clearly states the module cannot be found.
❓ Predict Output
expert2:00remaining
Output of a Node.js script using top-level await
What will this script output when run with Node.js 20+?
Javascript
const wait = ms => new Promise(resolve => setTimeout(resolve, ms)); await wait(100); console.log('Done waiting');
Attempts:
2 left
💡 Hint
Node.js 20+ supports top-level await in modules.
✗ Incorrect
Top-level await pauses execution until the promise resolves, then logs the message.