JSFiddle - React, Tailwind, and code Playground

JavaScript

function UrlExists(url) {
        var xhr = new XMLHttpRequest();
        xhr.open("GET", url, true); // true => async request
        xhr.onload = function (e) {
            if (xhr.readyState === 4) {
                if (xhr.status === 200) {
                    alert("url exists:\r\n" + xhr.responseURL);
                } else {
                    alert("not found or unexpected response:\r\n" + xhr.responseURL);
                }
            }
        };
        xhr.onerror = function (e) {
            console.error(xhr.statusText);
        };
        xhr.send(null);
    }
    var url = '/'; // just an example, get web app root
    UrlExists(url);
    UrlExists("/badurl");