Bird
0
0

What will the following code output?

medium📝 component behavior Q13 of 15
Node.js - URL and Query String Handling
What will the following code output?
const params = new URLSearchParams('color=blue&size=medium');
params.set('size', 'large');
console.log(params.toString());
Acolor=blue&size=medium
Bcolor=blue
Ccolor=blue&size=large
Dsize=large&color=blue
Step-by-Step Solution
Solution:
  1. Step 1: Understand params.set()

    The set method updates the value of the 'size' parameter from 'medium' to 'large'.
  2. Step 2: Check the output of toString()

    The toString() method returns the query string with updated parameters in the order they were added.
  3. Final Answer:

    color=blue&size=large -> Option C
  4. Quick Check:

    set() updates value, toString() shows updated string [OK]
Quick Trick: set() changes value; toString() shows updated query [OK]
Common Mistakes:
  • Assuming set() adds a new parameter without replacing
  • Thinking order of parameters changes
  • Forgetting to call toString() to see the string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes