Bird
0
0

What is wrong with this code?

medium📝 Debug Q7 of 15
Node.js - HTTP Module
What is wrong with this code?
const querystring = require('querystring');
const parsed = querystring.parse('foo=bar&baz');
console.log(parsed.baz);
Aconsole.log syntax is invalid
Bparse() cannot handle multiple parameters
CThe query string is missing a value for 'baz'
Dquerystring module does not support parsing
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the query string format

    'foo=bar&baz'; 'baz' appears without an '=' followed by a value, so it is treated as the key 'baz' with an empty string value.
  2. Step 2: Understand parse() behavior

    parsed.baz will be an empty string, not undefined or error.
  3. Final Answer:

    The query string is missing a value for 'baz' -> Option C
  4. Quick Check:

    Missing value keys become empty strings [OK]
Quick Trick: Keys without '=' get empty string values [OK]
Common Mistakes:
  • Expecting error for missing value
  • Thinking parse() fails on incomplete pairs
  • Confusing empty string with undefined

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes