Como verificar se o elemento DOM do objeto

/**
* Check is object a DOM element

*

* ... usage ...

* // isDomElement( element )

*

*
@param elem
* @returns {boolean|*}

*/

const isDomElement = (elem = null) => {
try {
if (typeof elem === "string" && elem != "") {
elem
= document.querySelector('#' + elem);
}

if (typeof elem === "undefined" || elem == null) {
return false;
}

throw "Parameter is not a number!";
} catch (e) {
return (typeof HTMLElement === "object" ? elem instanceof HTMLElement : elem != "" && typeof elem === "object" && elem !== null && elem.nodeType === 1 && typeof elem.nodeName === "string" && typeof elem.ownerDocument === "object" && elem);
}
};