Challenge - 5 Problems
Node.js Exit Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the exit code of this Node.js script?
Consider this Node.js script. What exit code will the process return when it finishes?
Node.js
process.exit(5);Attempts:
2 left
💡 Hint
The number passed to process.exit() is the exit code.
✗ Incorrect
process.exit(5) immediately stops the Node.js process and returns exit code 5 to the operating system.
❓ Predict Output
intermediate2:00remaining
What happens if you call process.exit() without arguments?
What exit code does Node.js use if process.exit() is called with no arguments?
Node.js
process.exit();
Attempts:
2 left
💡 Hint
Default exit code when none is specified is zero.
✗ Incorrect
Calling process.exit() without arguments exits with code 0, which means success.
❓ component_behavior
advanced2:00remaining
What will this script output before exiting?
Analyze this script. What will it print before the process exits?
Node.js
console.log('Start'); process.exit(2); console.log('End');
Attempts:
2 left
💡 Hint
process.exit stops the process immediately.
✗ Incorrect
The first console.log prints 'Start'. Then process.exit(2) stops the process immediately, so 'End' is never printed.
📝 Syntax
advanced2:00remaining
Which option causes a syntax error?
Which of these process.exit calls will cause a syntax error in Node.js?
Attempts:
2 left
💡 Hint
Check the syntax for calling functions in JavaScript.
✗ Incorrect
process.exit 1; is missing parentheses and will cause a syntax error.
🔧 Debug
expert2:00remaining
Why does this script exit?
This script calls process.exit(0) inside a setTimeout. Why does the process exit?
Node.js
setTimeout(() => {
process.exit(0);
}, 1000);
setInterval(() => {
console.log('Running');
}, 500);Attempts:
2 left
💡 Hint
process.exit stops the process immediately when called.
✗ Incorrect
The setTimeout calls process.exit(0) after 1 second, which stops the process immediately, even if setInterval is running.