Bird
Raised Fist0
Node.jsframework~20 mins

Node.js built-in debugger in Node.js - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Node.js Debugger Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
How to start the Node.js built-in debugger?
Which command correctly starts the Node.js built-in debugger for a script named app.js?
Anode --inspect app.js
Bnode --debug-brk app.js
Cnode debug app.js
Dnode --inspect-brk app.js
Attempts:
2 left
💡 Hint
Think about the original command to launch the built-in CLI debugger.
component_behavior
intermediate
2:00remaining
What happens when you use debugger; in Node.js code?
If you run a Node.js script with the built-in debugger and the code contains a debugger; statement, what will happen when execution reaches that line?
Node.js
console.log('Start');
debugger;
console.log('End');
AThe <code>debugger;</code> line is ignored and execution continues immediately.
BExecution pauses and waits for debugger commands before continuing.
CThe script throws a syntax error and stops.
DExecution skips the <code>debugger;</code> line and logs only 'End'.
Attempts:
2 left
💡 Hint
Think of debugger; as a breakpoint in the code.
📝 Syntax
advanced
2:00remaining
Identify the correct command to start Node.js debugger and break on first line
Which command starts the Node.js built-in debugger and pauses execution on the first line of server.js?
Anode debug --brk server.js
Bnode debug --break server.js
Cnode debug server.js --break
Dnode --inspect server.js
Attempts:
2 left
💡 Hint
Look for the correct flag to break on the first line with the built-in debugger.
🔧 Debug
advanced
2:00remaining
What error occurs if you run node debug without a script?
What error message or behavior occurs when you run node debug without specifying a script file?
AError: No script specified. Usage: node debug <script.js>
BSyntaxError: Unexpected end of input
CThe debugger starts but immediately exits with no message.
DReferenceError: script is not defined
Attempts:
2 left
💡 Hint
Think about what the debugger expects as input.
state_output
expert
3:00remaining
What is the output of this Node.js debugger session?
Given the code below and running node debug test.js, what is the output after typing repl and then x + y in the debugger?
Node.js
const x = 5;
const y = 10;
debugger;
console.log(x + y);
AReferenceError: x is not defined
BSyntaxError: Unexpected identifier
Cundefined
D15
Attempts:
2 left
💡 Hint
Variables declared before the debugger statement are accessible in the REPL.

Practice

(1/5)
1. What is the primary purpose of the Node.js built-in debugger?
easy
A. To pause and inspect code execution to find bugs
B. To speed up the execution of Node.js programs
C. To automatically fix syntax errors in code
D. To deploy Node.js applications to the cloud

Solution

  1. Step 1: Understand the debugger's role

    The Node.js built-in debugger allows developers to pause code execution and inspect variables and flow.
  2. Step 2: Compare options to debugger purpose

    Only To pause and inspect code execution to find bugs describes pausing and inspecting code to find bugs, which matches the debugger's function.
  3. Final Answer:

    To pause and inspect code execution to find bugs -> Option A
  4. Quick Check:

    Debugger purpose = pause and inspect [OK]
Hint: Debugger = pause and inspect code to find bugs [OK]
Common Mistakes:
  • Thinking debugger speeds up code
  • Confusing debugger with auto-fix tools
  • Assuming debugger deploys apps
2. Which command correctly starts the Node.js built-in debugger for a script named app.js?
easy
A. node debug app.js
B. node run app.js
C. node inspect app.js
D. node start app.js

Solution

  1. Step 1: Recall debugger start commands

    The modern way to start the Node.js debugger is using node inspect followed by the script name.
  2. Step 2: Check each option

    node inspect app.js uses node inspect app.js, which is correct. node debug app.js uses deprecated node debug. Options B and D are invalid commands.
  3. Final Answer:

    node inspect app.js -> Option C
  4. Quick Check:

    Start debugger = node inspect [OK]
Hint: Use 'node inspect' to start debugger, not 'node debug' [OK]
Common Mistakes:
  • Using 'node debug' which is deprecated
  • Using 'node run' or 'node start' which don't start debugger
  • Confusing command syntax order
3. Given this code snippet with debugger statements:
function add(a, b) {
  debugger;
  return a + b;
}

console.log(add(2, 3));

What happens when you run node inspect script.js on this file?
medium
A. The program runs without pausing and prints 5 immediately
B. The program crashes with an exception
C. SyntaxError occurs due to debugger statement
D. Execution pauses at the debugger line before returning the sum

Solution

  1. Step 1: Understand debugger statement effect

    The debugger; statement causes the debugger to pause execution at that line when running under a debugger.
  2. Step 2: Analyze program flow

    Running node inspect pauses at the debugger; line inside add before returning the sum, allowing inspection.
  3. Final Answer:

    Execution pauses at the debugger line before returning the sum -> Option D
  4. Quick Check:

    Debugger statement pauses execution under debugger [OK]
Hint: Debugger statement pauses code only when debugger runs [OK]
Common Mistakes:
  • Thinking debugger statement causes syntax error
  • Assuming program runs without pause under debugger
  • Confusing debugger statement with console.log
4. You run node inspect app.js but the debugger does not pause at your debugger; statement inside a function. What is a likely cause?
medium
A. The debugger command is misspelled
B. You forgot to save the file after adding the debugger statement
C. Node.js version does not support debugger
D. Debugger statements only work in browser JavaScript

Solution

  1. Step 1: Check file changes

    If the file was not saved after adding debugger;, the running code won't include it, so debugger won't pause.
  2. Step 2: Evaluate other options

    Debugger command spelling doesn't affect pause at debugger;. Node.js supports debugger in recent versions. Debugger statements work in Node.js, not only browsers.
  3. Final Answer:

    You forgot to save the file after adding the debugger statement -> Option B
  4. Quick Check:

    Unsaved file = debugger ignored [OK]
Hint: Always save files before debugging to include changes [OK]
Common Mistakes:
  • Assuming debugger statements only work in browsers
  • Ignoring file save before running debugger
  • Blaming Node.js version without checking
5. You want to debug a Node.js script and step through each line inside a loop. Which command should you use after starting node inspect script.js to move to the next line without entering functions?
hard
A. next
B. cont
C. step
D. out

Solution

  1. Step 1: Understand debugger commands

    cont continues running until next breakpoint, step enters functions, next moves to next line without entering functions, out steps out of current function.
  2. Step 2: Choose command for stepping through loop lines

    To move line by line in the current function (like inside a loop) without entering called functions, next is the correct command.
  3. Final Answer:

    next -> Option A
  4. Quick Check:

    Step over lines = next [OK]
Hint: Use 'next' to step over lines without entering functions [OK]
Common Mistakes:
  • Using 'cont' which runs without pausing
  • Using 'step' which enters functions
  • Using 'out' which exits current function