javascript check if class has method code example
Example 1: javascript check if element has class
if(document.getElementById("myElmentID").classList.contains("hidden")){
}
Example 2: check if a class exists javascript
const element = document.querySelector("#box");
element.classList.contains("active");
Example 3: check if object has method javascript
if(typeof myObj.prop2 === 'function') {
alert("It's a function");
} else if (typeof myObj.prop2 === 'undefined') {
alert("It's undefined");
} else {
alert("It's neither undefined nor a function. It's a " + typeof myObj.prop2);
}