Bird
0
0

How can you create a new URL object for a relative path /about when you only have the base URL https://example.com?

hard📝 Application Q9 of 15
Node.js - URL and Query String Handling
How can you create a new URL object for a relative path /about when you only have the base URL https://example.com?
Anew URL('about', 'https://example.com')
Bnew URL('https://example.com' + '/about')
Cnew URL('/about')
Dnew URL('/about', 'https://example.com')
Step-by-Step Solution
Solution:
  1. Step 1: Understand URL constructor with base

    The URL constructor accepts a relative path as the first argument and a base URL as the second argument.
  2. Step 2: Check the correct syntax

    Using new URL('/about', 'https://example.com') correctly resolves the full URL.
  3. Final Answer:

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

    Use new URL(relative, base) for relative URLs [OK]
Quick Trick: Pass base URL as second argument for relative URLs [OK]
Common Mistakes:
  • Concatenating strings manually
  • Omitting base URL for relative paths
  • Using relative path without leading slash

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes