0
0
Node.jsframework~20 mins

process.exit and exit codes in Node.js - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Node.js Exit Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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);
A1
B0
C5
Dundefined
Attempts:
2 left
💡 Hint
The number passed to process.exit() is the exit code.
Predict Output
intermediate
2: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();
A1
BNaN
Cundefined
D0
Attempts:
2 left
💡 Hint
Default exit code when none is specified is zero.
component_behavior
advanced
2: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');
AEnd
BStart
CStart\nEnd
DNo output
Attempts:
2 left
💡 Hint
process.exit stops the process immediately.
📝 Syntax
advanced
2:00remaining
Which option causes a syntax error?
Which of these process.exit calls will cause a syntax error in Node.js?
Aprocess.exit 1;
Bprocess.exit('1');
Cprocess.exit();
Dprocess.exit(0);
Attempts:
2 left
💡 Hint
Check the syntax for calling functions in JavaScript.
🔧 Debug
expert
2: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);
ABecause setTimeout is delayed, but process.exit is called after 1 second, the process exits.
BBecause process.exit is asynchronous and delayed, the process stays alive.
CBecause setInterval prevents process.exit from stopping the process.
DBecause setInterval keeps the event loop alive, process.exit is never called.
Attempts:
2 left
💡 Hint
process.exit stops the process immediately when called.