1const url = new URL(url [, base])
2// KEEP IN MIND that new URL(...) adds the first parameter to the second one
3
4// examples:
5
6// Base urls
7let m = 'https://developer.mozilla.org';
8
9new URL('en-US/docs', m);
10// => 'https://developer.mozilla.org/en-US/docs'
11// adds the first parameter to second one
12
13new URL('/en-US/docs', "https://developer.mozilla.org/fr-FR/toto");
14// => 'https://developer.mozilla.org/en-US/docs'
15// the / in start of '/en-US/docs' makes the link start from base and ignore other routes
16
17new URL('en-US/docs', "https://developer.mozilla.org/fr-FR/toto");
18// => 'https://developer.mozilla.org/fr-FR/en-US/docs'
19// this time the url starts from the last route, then it adds first parameter to it
20
21new URL('http://www.example.com', m);
22// => 'http://www.example.com/'
23// first param replaces second one because it has it's own origin
24