Bird
0
0

What is wrong with this code snippet?

medium📝 Debug Q6 of 15
Node.js - URL and Query String Handling
What is wrong with this code snippet?
const myUrl = URL('https://example.com');
console.log(myUrl.hostname);
Ahostname is not a valid property
BURL constructor does not accept strings
CMissing 'new' keyword when creating URL object
Dconsole.log syntax is incorrect
Step-by-Step Solution
Solution:
  1. Step 1: Check how URL objects are created

    The URL class requires the new keyword to instantiate an object.
  2. Step 2: Identify the error cause

    Calling URL as a function without new will throw a TypeError.
  3. Final Answer:

    Missing 'new' keyword when creating URL object -> Option C
  4. Quick Check:

    URL object creation needs 'new' [OK]
Quick Trick: Always use 'new' with URL constructor [OK]
Common Mistakes:
  • Omitting 'new' keyword
  • Assuming URL is a function, not a class
  • Misunderstanding hostname property

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes