Bird
0
0

Which Node.js URL constructor usage correctly creates a URL from a relative path '/about' with base 'https://example.com'?

easy📝 Conceptual Q2 of 15
Node.js - URL and Query String Handling
Which Node.js URL constructor usage correctly creates a URL from a relative path '/about' with base 'https://example.com'?
Anew URL('/about', 'https://example.com')
Bnew URL('https://example.com', '/about')
Cnew URL('about', 'https://example.com')
Dnew URL('https://example.com/about')
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct URL constructor parameters

    The URL constructor takes the relative path first, then the base URL as the second argument.
  2. Step 2: Validate the options

    new URL('/about', 'https://example.com') correctly uses new URL('/about', 'https://example.com'). new URL('https://example.com', '/about') reverses parameters, C misses leading slash, D uses only absolute URL without base.
  3. Final Answer:

    new URL('/about', 'https://example.com') -> Option A
  4. Quick Check:

    URL(relative, base) = B [OK]
Quick Trick: URL constructor: first relative, then base URL [OK]
Common Mistakes:
  • Swapping relative and base URL arguments
  • Omitting leading slash in relative path

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes