Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q6 of 15
Node.js - URL and Query String Handling
Identify the error in this code snippet:
const params = new URLSearchParams('foo=bar');
params.set('foo');
console.log(params.toString());
Aset() requires two arguments: key and value
BURLSearchParams cannot be created from a string
CtoString() is not a method of URLSearchParams
DMissing semicolon after set()
Step-by-Step Solution
Solution:
  1. Step 1: Check set() method usage

    The set() method requires two arguments: the key and the value to set.
  2. Step 2: Analyze the code

    Here, set('foo') is called with only one argument, causing an error.
  3. Final Answer:

    set() requires two arguments: key and value -> Option A
  4. Quick Check:

    set() needs key and value parameters [OK]
Quick Trick: Always provide key and value to set() [OK]
Common Mistakes:
  • Calling set() with one argument
  • Confusing set() with append()
  • Ignoring method argument requirements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes