const originalURL = "https://www.example.com/search?q=JavaScript & Web Development";
const encodedURL = encodeURIComponent(originalURL);

console.log(encodedURL);
// 출력: "https%3A%2F%2Fwww.example.com%2Fsearch%3Fq%3DJavaScript%20%26%20Web%20Development"

const decodedURL = decodeURIComponent(encodedURL);

console.log(decodedURL);
// 출력: "https://www.example.com/search?q=JavaScript & Web Development"
decodeURIComponent(encodedURI)
const originalURL = "https://www.example.com/page?query=hello world";
const encodedURL = encodeURIComponent(originalURL);

console.log(encodedURL);
// 출력: "https%3A%2F%2Fwww.example.com%2Fpage%3Fquery%3Dhello%20world"

const decodedURL = decodeURIComponent(encodedURL);

console.log(decodedURL);
// 출력: "https://www.example.com/page?query=hello world"
function decodeURL(encodedURL) {
    try {
        return decodeURIComponent(encodedURL);
    } catch (error) {
        console.error(error);
        return null;
    }
}

const encodedURL = "";

const decodedURL = decodeURL(encodedURL);

if (decodedURL) {
    console.log(decodedURL);
} else {
    console.log("Invalid URL.");
}

 // 출력: "Invalid URL."

caniuse.com에서 더 자세한 정보를 확인해 보세요.