1const uri = 'https://mozilla.org/?x=шеллы';
2const encoded = encodeURI(uri);
3console.log(encoded);
4// expected output: "https://mozilla.org/?x=%D1%88%D0%B5%D0%BB%D0%BB%D1%8B"
5
6try {
7 console.log(decodeURI(encoded));
8 // expected output: "https://mozilla.org/?x=шеллы"
9} catch (e) { // catches a malformed URI
10 console.error(e);
11}
1var myOtherUrl =
2 "http://example.com/index.html?url=" + encodeURIComponent(myUrl);