Js to determine whether js functions variables exist or not simple sample code

  • 2020-03-30 02:13:45
  • OfStack

The core code


//Does the specified function exist
function isExitsFunction(funcName) {
  try {
    if (typeof(eval(funcName)) == "function") {
      return true;
    }
  } catch(e) {}
  return false;
}
//Whether the specified variable exists
function isExitsVariable(variableName) {
  try {
    if (typeof(variableName) == "undefined") {
      //alert("value is undefined"); 
      return false;
    } else {
      //alert("value is true"); 
      return true;
    }
  } catch(e) {}
  return false;
}

More judgment can be found in this article: (link: #)


Related articles: