Complete the code to create a new URL object with an absolute URL string.
const url = new URL([1]);The URL constructor requires an absolute URL string or a base URL to resolve relative URLs. Here, we provide an absolute URL string.
Complete the code to resolve a relative URL against a base URL.
const base = new URL('https://example.com/folder/'); const resolved = new URL([1], base);
When resolving a relative URL against a base, a simple filename like 'file.txt' appends to the base path.
Fix the error in the code to correctly create a URL from a relative path and base URL.
const base = new URL('https://example.com/dir/'); const url = new URL([1], base);
To resolve a relative file inside the base directory, use just the filename 'file.txt'. Using 'dir/file.txt' repeats the directory.
Fill both blanks to create a URL object resolving a relative path with a base URL string.
const url = new URL([1], [2]);
The first argument is the relative path 'page.html' and the second is the base URL string. This resolves to 'https://example.com/base/page.html'.
Fill all three blanks to create a URL object and extract its pathname and origin.
const url = new URL([1], [2]); const path = url.[3];
The URL is created by resolving 'subdir/file.txt' against the base URL. The pathname property gives the path part of the URL.