Bird
0
0

Why does the URL constructor in Node.js require a base URL when given a relative path?

hard📝 Conceptual Q10 of 15
Node.js - URL and Query String Handling
Why does the URL constructor in Node.js require a base URL when given a relative path?
ATo resolve the relative path into a full absolute URL
BBecause relative paths are invalid in URLs
CTo validate the syntax of the relative path
DTo convert the relative path into a file system path
Step-by-Step Solution
Solution:
  1. Step 1: Understand purpose of base URL

    The base URL provides context to convert a relative path into a full absolute URL.
  2. Step 2: Clarify why base is needed

    Without a base, the relative path cannot be resolved to a complete URL string.
  3. Final Answer:

    To resolve the relative path into a full absolute URL -> Option A
  4. Quick Check:

    Base URL resolves relative paths = A [OK]
Quick Trick: Base URL needed to make relative path absolute [OK]
Common Mistakes:
  • Thinking relative paths are invalid alone
  • Confusing URL resolution with file system paths

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes