new URL(url, [base]) url full URL or only path (if base is set) base optional base URL: if set and url argument has only path, then the URL is generated relative to base built-in URL class provides a convenient interface for creating and parsing URLs sometimes it can be really helpful can pass URL objects to networking methods instead of a string Create const url1 = new URL('https://javascript.info/profile/admin') // https://javascript.info/profile/admin const url2 = new URL('/profile/admin', 'https://javascript.info') // https://javascript.info/profile/admin const newUrl = new URL('tester', url1) // https://javascript.info/profile/tester Properties const url = new URL('https://site.com:8080/path/page?p1=v1&p2=v2#hash') url.href full url "https://site.com:8080/path/page?p1=v1&p2=v2#hash" url.toString() same url.protocol "https:" , ends with the colon character : url.search "?p1=v1&p2=v2" , a string of parameters, starts with the question mark ? url.host "site.com:8080" url.pathname "/path/page" url.hash "#hash" , starts with the hash character # url.searchParams iterable object with search parameters searchParams url.searchParams.append(name, value) add the parameter by name url.searchParams.delete(name) remove the parameter by name url.searchParams.get(name) get the parameter by name url.searchParams.getAll(name) get all parameters with the same name, e.g. ?user=John&user=Pete url.searchParams.has(name) check for the existence of the parameter by name, url.searchParams.set(name, value) set/replace the parameter, parameters are automatically encoded url.searchParams.sort() sort parameters by name, rarely needed const url = new URL('https://google.com/search') url.searchParams.set('q', 'test me!') // https://google.com/search?q=test+me%21 url.searchParams.set('tbs', 'qdr:y'); // https://google.com/search?q=test+me%21&tbs=qdr%3Ay for(let [name, value] of url.searchParams) { alert(`${name}=${value}`) // q=test me! // tbs=qdr:y } Encoding RFC3986 standard defines which characters are allowed in URLs and which are not not allowed, must be encoded for instance non-latin letters and spaces – replaced with their UTF-8 codes, prefixed by % Use URL object not to think about encoding, it will take care of it automatically const url = new URL('https://ru.wikipedia.org/wiki/Тест') url.searchParams.set('key', 'ъ') // https://ru.wikipedia.org/wiki/%D0%A2%D0%B5%D1%81%D1%82?key=%D1%8A const url = new URL('http://site.com/привет') url.toString() // "http://site.com/%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82" If we use a string for URL, we need to encode/decode special characters manually There are built-in functions for that encodeURI() , decodeURI() , encodeURIComponent() , decodeURIComponent() encodeURI() encodes URL as a whole decodeURI() decodes it back encodeURIComponent() encodes a URL component, such as a search parameter, or a hash, or a pathname decodeURIComponent() decodes it back encodeURI encodes only characters that are totally forbidden in URL encodeURIComponent encodes same characters, plus # $ & + , / : ; = ? @ For a whole URL we can use encodeURI ... // correct encodeURI('http://site.com/привет') // "http://site.com/%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82" // incorrect encodeURIComponent('http://site.com/привет') // "http%3A%2F%2Fsite.com%2F%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82" For URL parameters we should use encodeURIComponent instead. const music = encodeURIComponent('Rock&Roll') const url = `https://google.com/search?q=${music}` // 'https://google.com/search?q=Rock%26Roll'