Recall & Review
beginner
What is the purpose of the URL class in Node.js?The URL class helps you create and manipulate URLs easily by breaking them into parts like protocol, hostname, pathname, and query parameters.Click to reveal answer
beginner
How do you add query parameters to a URL using Node.js URL class?
You use the URLSearchParams object to add or update query parameters. For example, url.searchParams.append('key', 'value') adds a new query parameter.
Click to reveal answer
beginner
What does the url.toString() method do?
It converts the URL object back into a full URL string that you can use in requests or display.
Click to reveal answer
intermediate
Why is it better to build URLs programmatically instead of string concatenation?
Building URLs programmatically avoids errors like missing slashes or wrong encoding. It ensures the URL parts are combined correctly and safely.
Click to reveal answer
beginner
Which Node.js module provides the URL class?
The URL class is available globally in Node.js since version 10, but it originally comes from the 'url' module.Click to reveal answer
Which method adds a query parameter to a URL object in Node.js?
✗ Incorrect
The correct method is url.searchParams.append() to add query parameters.
What does url.toString() return?
✗ Incorrect
url.toString() returns the full URL as a string.
Why should you avoid building URLs by simple string concatenation?
✗ Incorrect
String concatenation can cause errors like missing slashes or incorrect encoding.
Which part of the URL can you change using the URL class properties?
✗ Incorrect
You can change protocol, hostname, pathname, and searchParams individually.
How do you create a new URL object in Node.js?
✗ Incorrect
You create a new URL object by calling new URL('https://example.com').
Explain how to build a URL with query parameters programmatically in Node.js.
Think about creating the URL object, adding parameters, then converting to string.
You got /3 concepts.
Why is using the URL class safer than manual string concatenation when building URLs?
Consider common mistakes when typing URLs by hand.
You got /4 concepts.