js check if file or folder exists code example
Example: javascript file exists check
// checking existence of file synchronously
function doesFileExist(urlToFile) {
var xhr = new XMLHttpRequest();
xhr.open('HEAD', urlToFile, false);
xhr.send();
return xhr.status !== 404;
}