要检查是否定义了JavaScript函数,请使用“ undefined”进行检查。
您可以尝试运行以下示例以检查是否在JavaScript中定义了函数-
<!DOCTYPE html>
<html>
<body>
<script>
function display() {
alert("演示文字!");
}
if ( typeof(display) === 'undefined') {
document.write('undefined');
} else {
document.write("Function is defined");
}
</script>
</body>
</html>