Bird
0
0

What will this code print?

medium📝 Predict Output Q5 of 15
Node.js - URL and Query String Handling
What will this code print?
const url = new URL('https://example.com/path?search=books');
url.searchParams.delete('search');
console.log(url.href);
Ahttps://example.com/path?search=books
Bhttps://example.com/path?
Chttps://example.com/path
Dhttps://example.com/
Step-by-Step Solution
Solution:
  1. Step 1: Understand searchParams.delete effect

    Deleting 'search' removes that query parameter from the URL.
  2. Step 2: Check resulting URL string

    After deletion, no query parameters remain, so URL is 'https://example.com/path' without trailing '?'.
  3. Final Answer:

    https://example.com/path -> Option C
  4. Quick Check:

    Deleting query param removes it cleanly [OK]
Quick Trick: Deleting query param removes it and '?' if none left [OK]
Common Mistakes:
  • Expecting query string to remain
  • Leaving trailing '?' after deletion
  • Confusing href and toString()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes